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 02:49

The apache firewall blocks the ip address. so to give access, use these commands:

firewall-cmd --permanent --zone=trusted --add-source=YOUR_IP/32

firewall-cmd --permanent --zone=trusted --add-port=3306/tcp

firewall-cmd --reload

查看更多
永恒的永恒
3楼-- · 2019-01-01 02:49

I faced the same problem. I checked and tried to set AllowTcpForwarding Yes but it was missing in my sshd_config so no help.I didn't change sshd_config or my.cnf. Make sure the ssh hostname is NOT the same with the mysql hostname(use localhost).

In workbench, choose + to add new connection and set the following:

  • connection method: standard TCP/IP over SSH
  • SSH Hostname: 192.168.0.50:22 (replace remote SSH server IP and port(optional))
  • SSH Username: sshuser
  • You can set password or add at the prompt
  • MYSQL Hostname: localhost or 127.0.0.1
  • MYSQL Server port:3306
  • You can set password or add at the prompt

Test connection. It should be successful then hit OK.Viola!

查看更多
看淡一切
4楼-- · 2019-01-01 02:51

I just set up mysql on a windows box. I got the OP's error when trying to connect with the Navicat MySql client on the same box. I had to specify 127.0.0.1 as the host, and that got it.

localhost, or the servers actual ip address both did not work.

查看更多
姐姐魅力值爆表
5楼-- · 2019-01-01 02:52

in my case, I had ALL: ALL in hosts.deny. Changing this to ALL: PARANOID solved my problem when connecting over ssh

查看更多
栀子花@的思念
6楼-- · 2019-01-01 02:52

When connecting to Mysql remotely, I got the error. I had this warning in /var/log/mysqld.log:

[Warning] IP address 'X.X.X.X' could not be resolved: Temporary failure in name resolution

I just added this line to /etc/hosts file:

X.X.X.X some_name

Problem solved! Not using skip-name-resolve caused some errors in my local app when connecting to MySQL.

查看更多
ら面具成の殇う
7楼-- · 2019-01-01 02:52

I had identical problem. To fix it I just changed host from localhost:3306 to just localhost. So error may acour when You sepcify unproper port for connection. It's better to leave it default.

查看更多
登录 后发表回答