Recently, the server was very unstable, so I re-installed the mysql and php services, but then I encountered a headache.
The following message is always prompted when you remotely connect to mysql:
Copy codeThe 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:
Copy codeThe 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)
Copy codeThe 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:
Copy codeThe 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.