php代码很简单:

$server="127.0.0.1";
println("Begin");
$link = mysql_connect($server,"mysql","mysql");
if (!$link) {
die('Could not connect: ' . mysql_error().mysql_errno());
}

linux本机下使用php mysql.php 可以查看运行结果,但是 在我的windows浏览器下报错:

Could not connect: Can't connect to MySQL server on '127.0.0.1' (13) 2003

原因:
#getsebool -a | grep httpd
[neo@neo phpMyTest]$ getsebool -a | grep httpd

发现 httpd_can_network_connect --> off
解决方案:
#setsebool httpd_can_network_connect 1

原来是 SELINUX,所以我一般直接关闭SELINUX和 iptables ip6tables

# 关闭SELINUX
chkconfig --level 12345 iptables off chkconfig --level 12345 ip6tables off service iptables stop service ip6tables stop 查看SELinux状态: 1、/usr/sbin/sestatus -v ##如果SELinux status参数为enabled即为开启状态 SELinux status: enabled 2、getenforce ##也可以用这个命令检查 关闭SELinux: 1、临时关闭(不用重启机器): setenforce 0 ##设置SELinux 成为permissive模式 ##setenforce 1 设置SELinux 成为enforcing模式 2、修改配置文件需要重启机器: 修改/etc/selinux/config 文件 将SELINUX=enforcing改为SELINUX=disabled

参考资料:

http://hi.baidu.com/zwfec/item/64ef5ed9bf1cb3feca0c397c

顺便再道一下:

CentOS下 无法ping外网IP

centos DNS 不能解析
装好centos时发现yum install vim时无法安装。原来DNS不能解析
配置vi /etc/resolv.conf 发现重启就没了。
最终解决 修改 vi /etc/sysconfig/network-scripts/ifcfg-Auto_eth0
添加
DNS1=8.8.8.8
DNS2=8.8.4.4
DNS3=192.168.1.1
重启网络 生成resolv.conf 配置
service network restart -------------
[root@localhost langxw]# ping 8.8.8.8
connect: 网络不可达 。原来没有下面的GATEWAY=192.168.1.1 TYPE=Ethernet
BOOTPROTO=none
IPADDR=192.168.1.121
PREFIX=24
GATEWAY=192.168.1.1
DEFROUTE=yes

CentOS下httpd下php 连接mysql 本机可以,外网报错Could not connect: Can't connect to MySQL server on '127.0.0.1' (13)2003 原因解析的更多相关文章

  1. CentOS下httpd下php 连接mysql 本机可以,127.0.0.1不能访问

    你看到的这个文章来自于http://www.cnblogs.com/ayanmw php代码很简单: $server="127.0.0.1"; println("Begi ...

  2. 3.django连接mysql数据库及安装mysqldb驱动报错解决办法

    1.在setting.py设置连接数据库 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'djang ...

  3. Linux下编译程序时,经常会遇到“undefined reference to XXX” 报错,

    Linux下编译程序时,经常会遇到“undefined reference to XXX” 报错, 这里总结一些可能的原因和解决方案,给需要的朋友: 说道undefined reference err ...

  4. 解决:eclipse导入android时工程下没有R文件的问题,以及style.xml文件报错

    解决:eclipse导入android时工程下没有R文件的问题,以及style.xml文件报错

  5. SpringBoot配置JDBC连接MySql数据库的时候遇到了报错:HikariPool-1 - Exception during pool initialization

    使用SpringBoot做JAVA开发时,JDBC连接MySql数据库的时候遇到了报错: ERROR 10392 --- [ main] com.zaxxer.hikari.pool.HikariPo ...

  6. Sqoop- sqoop将mysql数据表导入到hive报错

    sqoop将mysql数据表导入到hive报错 [root@ip---- lib]# sqoop import --connect jdbc:mysql://54.223.175.12:3308/gx ...

  7. 安装mysql驱动之 mysqlclient 出现的报错处理(ubuntu16.04)

    首先 更新软件! sudo apt-get update 然后尝试安装mysqlclient,报错 后执行下面的步骤 安装mysql驱动之 mysqlclient 出现的报错信息处理 报错1: OSE ...

  8. mysql修改后启动my.cnf报错Starting MySQL... ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).

    mysql中文乱码解决 mysql修改my.cnf后启动报错Starting MySQL... ERROR! The server quit without updating PID file (/v ...

  9. 【mysql】 load local data infield 报错 ERROR 1148 (42000): The used command is not allowed with this MySQL version

    mysql> load data local infile '/Users/flint/learn/mysql/pet' into table bx_pet; 执行报错 ERROR 1148 ( ...

随机推荐

  1. Python中collections.defaultdict()使用

    一个小示例 from collections import defaultdict import json def tree(): return defaultdict(tree) users = t ...

  2. 003.FTP客户端连接

    一 命令行连接 注意: 1:命令行连接不支持目录下载,使用mget也只会将目录下文件下载,不会下载目录本身. 2:命令行连接不支持断点续传. ftp [服务端IP] -help #获取帮助 - -mg ...

  3. Python3 计算相关系数

    # -*- coding: utf-8 -*- """ Created on Mon Jan 8 19:36:48 2018 @author: markli " ...

  4. UI自动化测试(一)简介及Selenium工具的介绍和环境搭建

    自动化测试简介 1.1何为自动化测试? 是把以人为驱动的测试转化为机器执行的一种过程,它是一种以程序测试程序的过程.换言之,就是以程序实现的方式来代替手工测试. 1.2自动化测试分类 分为功能自动化测 ...

  5. BZOJ2888 : 资源运输

    显然资源集合处就是树的重心,这题需要动态维护树的重心. 每个连通块以重心为根,用link-cut tree维护每个点的子树大小以及子树内所有点到它的距离和. 合并两个连通块时,考虑启发式合并,暴力往大 ...

  6. rails 数据迁移 -migration

    1.创建一个fruits 项目: rails new fruits -d mysql --skip-bundle 2.修改Gemfile: source 'https://gems.ruby-chin ...

  7. CentOS 7搭建KVM在线管理面板WebVirtMgr之使用SSH授权登录

    环境:CentOS 7.4 1.创建SSH私钥和ssh配置选项(在安装了WebVirtMgr的系统上): # 切换到nginx用户su - nginx -s /bin/bash # 生产ssh密钥 s ...

  8. [原创]App性能测试指标篇

    [原创]App性能测试指标篇 目前由于苹果,三星等大厂对智能手机的研发及投入,使的智能手机发展非常迅速,每个人手中都有一些离不开生活的App,如:微信,微博,百度或是各游戏App等,但是到底App性能 ...

  9. Redis使用小结

    Redis官方没有windows版本的,对于Windows环境的redis,有如下两个方案 微软的移植版本,但只支持到3.2 下载地址 win10及以上的版本直接通过win10的liunx子系统执行 ...

  10. jtagger Versatile multiprogrammer for FPGAs, MCUs, etc.

    jtagger Versatile multiprogrammer for FPGAs, MCUs, etc. Well, it's not really just a jtagger, but I' ...