【发布时间】:2011-05-03 22:54:13
【问题描述】:
我在新安装的服务器中出现了奇怪的情况,这次谷歌似乎无法帮助我。 我无法从我的 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
是解决方案。
【问题讨论】:
-
Fedora11远程服务器是Win2k8