我在新安装的服务器上有奇怪的情况,谷歌这次似乎帮不了我。我不能从我的php代码连接到(远程) mysql。当我尝试从同一台服务器上的命令行连接时,连接成功了。
无法连接:无法连接到'MYSQL.SERVER‘上的MySQL服务器(13)
以下是命令行中的代码和连接尝试
[u1@bosko httpdocs]$ cat test.php
<?
$link = mysql_connect('MYSQL.SERVER', 'testusersimon', '123456');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
[u1@bosko httpdocs]$ mysql -h MYSQL.SERVER -utestusersimon --password=123456
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 352108
Server version: 5.0.45-community-nt-log MySQL Community Edition (GPL)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> quit
Bye
我尝试在mod_php模式和FastCGI模式下运行php脚本,检查"/etc/php.d/mysql.ini“是否出现在phpinfo()以及mysql、mysqli和pdo_mysql部分中。
但结果是一样的,我知道这很简单,但我就是做不到。请帮助:)
编辑:问题出在SElinux上
setsebool -P httpd_can_network_connect_db=1
才是解决之道。
https://stackoverflow.com/questions/4078205
复制相似问题