手机
当前位置:查字典教程网 >编程开发 >mysql数据库 >CentOS下php使用127.0.0.1不能连接mysql的解决方法
CentOS下php使用127.0.0.1不能连接mysql的解决方法
摘要:php代码很简单:代码如下:$server="127.0.0.1";println("Begin");$link=mysql_connect...

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

【CentOS下php使用127.0.0.1不能连接mysql的解决方法】相关文章:

linux忘记mysql密码处理方法

MYSQL出现" Client does not support authentication "的解决方法

linux下备份MYSQL数据库的方法

CMD下查询Mysql中文乱码的解决方法

mysql命令提示行连接乱码的解决

mysql中文乱码的一些解决方案

MySQL错误Forcing close of thread的两种解决方法

通过mysql show processlist 命令检查mysql锁的方法

mysql 忘记密码的解决方法(linux和windows小结)

mysql 中文乱码 解决方法集锦

精品推荐
分类导航