php访问mysql出错
时间:2010-05-28 来源:uranusllj
My php connect:
$host = "192.168.1.197";
$user = "root";
$pass = "rootpassword";
$database = "sample1";
#$con=@mysql_connect("$host","$user","$pass") or die('Error connecting to mysql');
$con = mysql_connect("$host", "username", "password") or die(mysql_error());
$db="$database"; @mysql_select_db($db, $con);
出现错误:Can't connect to MySQL server on '192.168.1.197' (13)
但是用mysql -h 192.168.1.197 -u root -p可以连接
故障原因:是因为client的selinux在做怪
把selinux关掉,并重启
mysql服务端配置文件my.cnf加上
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
并重启就可以访问了
$host = "192.168.1.197";
$user = "root";
$pass = "rootpassword";
$database = "sample1";
#$con=@mysql_connect("$host","$user","$pass") or die('Error connecting to mysql');
$con = mysql_connect("$host", "username", "password") or die(mysql_error());
$db="$database"; @mysql_select_db($db, $con);
出现错误:Can't connect to MySQL server on '192.168.1.197' (13)
但是用mysql -h 192.168.1.197 -u root -p可以连接
故障原因:是因为client的selinux在做怪
把selinux关掉,并重启
mysql服务端配置文件my.cnf加上
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
并重启就可以访问了
相关阅读 更多 +