How to solve the problem of MySQL remote connection loss (LostconnectiontoMySQLserver) is very unstable recently on the server, so I reinstalled the mysql and php services, but then I encountered a headache.
The following message is always prompted when you remotely connect to mysql:
The code is as follows: Lost connection to MySQL server at 'Reading initial communication packet ', system error: 0
Obviously, this is a connection error that is lost during connection initialization.
Google commented out bind-address = 127.0.0.1 in the configuration file for a long time.
However, my configuration file is not configured, and all kinds of searches fail. Today, I accidentally saw a configuration posted by a person who encountered the same problem on the internet. I found that he had another sentence about configuring skip-name-resolve, I changed my mind and restarted the mysql service. The remote connection was connected at once. it was speechless.
In fact, the problem is very simple, because the MySQL configuration file is not configured for remote connection by default, you just need to change the MySQL configuration file.
The specific steps are as follows, hoping to help students who encounter the same problem:
Find and modify the my. cnf file. In different Linux systems, my. cnf is placed in different locations. Here we use Ubuntu Server as an example. for other systems, please find the path of my. cnf as needed. It is generally stored only in/etc/my. cnf or/etc/mysql/my. cnf.
First, use vim to open my. cnf:
The code is as follows:
Vim/etc/mysql/my. cnf
Check whether the local loopback address is bound. If yes, comment out the following text: (add the # sign before the text)
The code is as follows:
Bind-address = 127.0.0.1
Find the parameter in [mysqld], create a new line after the configuration, and add the following parameter:
Skip-name-resolve
Save the file and restart MySQL:
The code is as follows:/etc/init. d/mysql restart
In this way, you will find that the problem has been solved! The remote connection will not be lost.