MySQL 连接丢失:系统错误:110
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12738346/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL connection lost: system error: 110
提问by David
I am trying to connect to my mySQL server through localhost on my dedicated server, but I keep getting the error:
我试图通过我专用服务器上的 localhost 连接到我的 mySQL 服务器,但我不断收到错误消息:
Lost connection to MySQL server at 'reading initial communication packet', system error: 110
CODE:
代码:
<?php
$link = mysql_connect('localhost', '****', '****');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
I haven't configured a firewall, so all ports should be open. What do I need to do? I have already checked several other similar questions, but none of them solved my problem. I am not connecting remotely.
我没有配置防火墙,所以所有端口都应该是开放的。我需要做什么?我已经检查了其他几个类似的问题,但没有一个解决了我的问题。我没有远程连接。
UPDATE
更新
Okay I found the issue with the connection to the server (I was connecting twice). I am able to connect now to the server, but when I run any query, the server returns FALSE. I have used this code before and it has worked before, but now that I have changed servers, it is not working.
好的,我发现了与服务器连接的问题(我连接了两次)。我现在可以连接到服务器,但是当我运行任何查询时,服务器返回 FALSE。我以前用过这个代码,以前也用过,但是现在换了服务器,就不行了。
Thanks,
谢谢,
David
大卫
采纳答案by Fathah Rehman P
May be you are connecting to your db with different parameters
可能是您使用不同的参数连接到数据库
回答by Andrew Teoh
I had a similar error code of "110" on server A. Have never changed the credentials, etc on both server A and B. However, my issue was that one server is actually communicating via the MySQL port: 3306 of server B, and I have recently setup firewall on server B, to allow remote MySQL access from server A. Server A was trying to connect to the Server B MySQL port 3306 and webserver would just timeout, issuing the MySQL error code and line error on the code.
我在服务器 A 上有一个类似的错误代码“110”。从未更改服务器 A 和 B 上的凭据等。但是,我的问题是一台服务器实际上是通过 MySQL 端口进行通信:服务器 B 的 3306,以及我最近在服务器 B 上设置了防火墙,以允许从服务器 A 进行远程 MySQL 访问。服务器 A 试图连接到服务器 B 的 MySQL 端口 3306,而网络服务器将超时,在代码上发出 MySQL 错误代码和行错误。
Solution that worked for me is:
sudo ufw status
对我有用的解决方案是:
sudo ufw status
Check if MySQL port is in the list, if not do this:
sudo ufw allow mysql
检查 MySQL 端口是否在列表中,如果没有,请执行以下操作:
sudo ufw allow mysql
This will add the ip4 and ip6 rules into the firewall approved list.
这会将 ip4 和 ip6 规则添加到防火墙批准列表中。
Good luck!
祝你好运!