How to solve the problem of MySQL remote connection loss (Lost connection to MySQL server)

Source: Internet
Author: User

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 = 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 =

Find the parameter in [mysqld], create a new line after the configuration, and add the following parameter:
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.