Lost connection to MySQL server at 'reading in

2019-01-01 02:30发布

I am getting error:

"Lost connection to MySQL server at 'reading initial communication packet, system error: 0"

while I am going to connect my db.

If I am using localhost everything is working fine. But when I am using my live IP address like below, it's getting error:

mysql_connect("202.131.xxx.106:xxxx", "xxxx", "xxxxx") or die(mysql_error());

标签: php mysql
23条回答
梦该遗忘
2楼-- · 2019-01-01 03:01

I have done below 3 steps then working for me.

1) bind-address = "YOUR MACHINE IP" in my.cnf file at /etc/my.cnf
2) Restart service by command : service httpd restart
3) GRANT ALL PRIVILEGES ON yourDB.* TO 'username'@'YOUR_APPLICATION_IP' IDENTIFIED BY 'YPUR_PASSWORD' WITH GRANT OPTION;
查看更多
长期被迫恋爱
3楼-- · 2019-01-01 03:02

I just had the same problem, but in my case I solved it with

service mysqld start

查看更多
长期被迫恋爱
4楼-- · 2019-01-01 03:03

Someone here: http://forums.mysql.com/read.php?52,166244,258515#msg-258515 suggests that it might be a firewall problem:

I have just had this problem and found it was my firewall. I use PCTools Firewall Plus and it wasn't allowing full access to MySQL. Once I changed that it was fine. Hope that helps.

Could that be it?

Also, somehere here: http://forums.mysql.com/read.php?52,151255,213970#msg-213970 suggests that it might be because the MySQL server is bound to the loop-back IP (127.0.0.1 / localhost) which effectively cuts you off from connecting from "outside".

If this is the case, you need to upload the script to the webserver (which is probably also running the MySQL server) and keep your server host as 'localhost'

查看更多
回忆,回不去的记忆
5楼-- · 2019-01-01 03:05

The problem on my case was MySQL being bind only to the lo on linux. in order to solve the problem i have edited the my.cnf (found at /etc/mysql/my.cnf) removing the line bind-address=127.0.0.1

this allows mysql to bind to any network interface

查看更多
无色无味的生活
6楼-- · 2019-01-01 03:05

The error means that it didn't receive a response from the port it expected to find the server on. The causes range from contacting the wrong machine (For one of a number of reasons) to the server not being on the expected port.

Check which port your server is bound to in /etc/mysql/my.cnf. Does that correspond to what is in your connect statement. If they match then try connecting with mysql from the server itself and from the command line of the machine where you are running the client. If it works form one place and not another then you may have a firewall / router configuration issue.

查看更多
登录 后发表回答