MySQL错误111无法连接到服务器 [英] MySQL Error 111 Can't connect to server

查看:118
本文介绍了MySQL错误111无法连接到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个connection.php文件,该文件应该连接到远程数据库. 这是代码:

I have a connection.php file that is suppose to connect to a remote database. Here is the code:

<?php
try {
    $conn = new PDO('mysql:host=IP;port=PORT;dbname=DBNAME', 'USERNAME', 'PASSWORD');
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
} 
?>

现在我相信我所有的变量都是正确的,因为我可以通过蟾蜍.我通过本地主机对自己的数据库连接使用了相同的PDO格式,并且工作正常.我不确定是什么问题.由于我可以使用 Toad ,因此我认为服务器已经允许远程访问它,但是我不确定.任何输入都会很好.

Now all my variables I believe are correct since I can connect to the database through Toad. I used this same PDO format for my own database connection through localhost and it works fine. I am not sure what the problem is. Since i can use Toad i believe that the server already allows remote access to it, but i am not sure on that. Any input would be nice.

这也是PDOException返回的错误:

Also this is the Error that PDOException is coming back with:

SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'IP' (111)

推荐答案

111表示连接被拒绝

这可能意味着您的MySQL服务器仅在监听localhost接口.

It probably means that your MySQL server is only listening the localhost interface.

如果您有这样的行:

skip-networking
bind-address = 127.0.0.1

您应该在my.cnf配置文件中对其进行注释(在行首添加#),然后重新启动MySQL.

You should comment them In your my.cnf configuration file (add a # at the beginning of the lines), and restart MySQL.

这篇关于MySQL错误111无法连接到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆