PHP无法连接,错误13到MySQL数据库(命令行即可) [英] php can't connect to mysql with error 13 (but command line can)
问题描述
我在新安装的服务器怪异的情况,看来,谷歌不能帮我这一次。
我无法连接到(远程)从我的PHP的code MySQL的。当我尝试从命令行连接在同一台服务器上的连接succseds。
无法连接:无法连接到
MySQL服务器
在mysql.server的(13)
块引用>下面是code和命令行连接尝试
[U1 @博斯科的httpdocs] $猫test.php的&LT ;?
$链接= mysql_connect('mysql.server的','testusersimon','123456');
如果(!$链接){
死亡(无法连接:'mysql_error());
}
回声连接成功;
mysql_close($链接);
?>[U1 @博斯科的httpdocs] $的mysql -h mysql.server的-utestusersimon --password = 123456
欢迎到MySQL监视器。命令终止与;或一个\\ g。
你的MySQL连接ID为352108
服务器版本:5.0.45社区-NT-登录MySQL社区版(GPL)版权所有(c)2000,2010,Oracle和/或其附属公司。保留所有权利。
该软件带有绝对没有担保。这是自由软件,
并欢迎您来修改和在GPL v2协议重新分配键入'帮助;为帮助或'\\ H'。键入'\\ c'来清除当前输入语句。MySQL的>放弃
再见我试图运行PHP脚本无论是在mod_php的模式和FastCGI的,
检查/etc/php.d/mysql.ini中的phpinfo(显示出来),以及MySQL中,mysqli的PDO_MYSQL和路段。但结果是一样的,我知道它的简单的东西,但我不能。
请帮助:)编辑:
问题是在SELinuxsetsebool -P httpd_can_network_connect_db = 1
是解决办法。
解决方案setsebool -P httpd_can_network_connect = 1
也将是一个有益的CLI命令,许多人参观了这个问题,才能让mysql_connet()连接从HTTP内(Apache)的请求到远程MySQL数据库服务器上,确保启用从httpd的网络连接在SELinux中通常位于在/ etc / SELinux的/ config中(默认情况下为prevent黑客利用你的httpd攻击其他机器禁用)。
I have weird situation in newly installed server, and it seems that Google can't help me this time. I can't connect to (remote) mysql from my php-code. When I try to connect from command line on the same server the connection succseds.
Could not connect: Can't connect to MySQL server on 'MYSQL.SERVER' (13)
Here is the code and the connect attempt from the command line
[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
I tried running the php script both in mod_php mode and in FastCGI, check that "/etc/php.d/mysql.ini" shows up in the phpinfo() as well as mysql,mysqli and pdo_mysql sections.
but the result was the same, I know its something simple but I just can't . Please help :)
Edit: The problem was with SElinux
setsebool -P httpd_can_network_connect_db=1
Was the solution.
解决方案setsebool -P httpd_can_network_connect=1
will also be a helpful CLI command to many people visiting this question, as to allow mysql_connet() connections from within HTTP (Apache) requests to a remote MySQL database server, ensure to enable Network Connections from httpd in SElinux usually located in /etc/selinux/config (disabled by default to prevent hackers from attacking other machines using your httpd).
这篇关于PHP无法连接,错误13到MySQL数据库(命令行即可)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!