我在新安装的服务器有奇怪的情况,似乎Google不能帮助我这次。 我无法连接到从我的php代码(远程)的MySQL。当我尝试从同一台服务器上的命令行进行连接时,连接失败。php无法连接到错误13(但命令行可以)的MySQL
无法连接:无法连接到 MySQL服务器 'mysql.server的'(13)
这里是代码,并通过命令行连接尝试
[[email protected] 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);
?>
[[email protected] 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
是解决办法。
你正在使用哪个操作系统? – Thariama 2010-11-02 13:44:38
Fedora11远程服务器是Win2k8 – SimSimY 2010-11-02 14:05:33