MySQL Remote Connection Loss problem Solution (Lost connection to MySQL server)

  • 2020-06-19 11:49:51
  • OfStack

Servers have been very unstable recently, so mysql and php services have been reinstalled, but then they have been having a lot of headaches.
Remote connection mysql is always prompted:

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

This is obviously an error where the connection is lost in the initialization phase.
google half a day is mostly said to comment out the configuration file in ES11en-ES12en = 127.0.0.1 this sentence.
However, my profile did not configure this sentence, and all kinds of searches failed. Today, I happened to see the configuration posted by a person with the same problem on the Internet. I found that he added one more sentence to the configuration of ES14en-ES15en-ES16en. He changed it with a try attitude and restarted the mysql service.
The problem is as simple as the MySQL configuration file is not configured for remote connections by default. You just need to change the MySQL configuration file.
The specific steps are as follows. I hope to help students with the same problem:
Locate and modify the my.cnf file. Under different Linux systems, ES26en.ES27en is placed in different positions. Here, Ubuntu Server is taken as an example. For other systems, please find the path of ES30en.cnf according to the situation. 1 a will only be stored in/etc/my cnf or/etc mysql/my cnf.
First, open ES41en. cnf with vim:


vim /etc/mysql/my.cnf

See if there is a configuration for binding local loopback addresses. If there is, comment out the following text :(just prefix the text with a hash sign)


bind-address = 127.0.0.1

Then find the parameters in the [mysqld] section, create a new row after the configuration, and add the following parameter:
skip-name-resolve
Save the file and restart MySQL:

/etc/init.d/mysql restart

Then you will find that the problem has been solved! The remote connection will not be lost.


Related articles: