首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >php无法连接到mysql,出现错误13 (但命令行可以)

php无法连接到mysql,出现错误13 (但命令行可以)
EN

Stack Overflow用户
提问于 2010-11-02 21:39:26
回答 3查看 58.1K关注 0票数 59

我在新安装的服务器上有奇怪的情况,谷歌这次似乎帮不了我。我不能从我的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

才是解决之道。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4078205

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档