MySQL MySQL lost connection to server during query problem solving method

Source: Internet
Author: User
Tags php database

Why: This happens when querying a database in MySQL, or modifying a larger table;
Scenario 1. Add a line under MySQL configuration file [Myslqd] to set skip-name-resolve. The MySQL service needs to be restarted.

Scenario 2: Add an IP to host name mapping in the Hosts file, such as: localhost. This is not a way to restart the MySQL service.
Solve this problem at three levels:
1. At the code level, you need to add roughly the following code to your PHP database connection.
if (In_array (Mysql_errno (), Array (2006, 2013))) {
Mysql_close ();
Mysql_connect (...);
mysql_query (...);
In other words, you can reconnect MySQL if you encounter a 2006,2013 error.
2. mysql level, need to configure some parameter my.cnf (but here is Linux, what about my Windows configuration?) )
Wait_timeout = x Timeout time of 600 seconds
Max_allowed_packet = y Maximum allowable data volume
Increase the value of x, y appropriately.
3. Generally this is not the case for all the sentences but a single table, please fix the table in general can solve such problems.
MySQL Error 2013:lost connection to MySQL server during query
Error code: 1153-got A packet bigger than ' Max_allowed_packet ' bytes
Modify Mysql.ini (online is said to be this file, looked for n long finally know where, my directory is in D:\MySQL_Data\MySQL Server 5.5 under the Mysql_data folder) file add the following code can be

Modify D:\MySQL\MySQL Server 5.5\my-huge.ini if you can't.
The max_allowed_packet=16m in the 16 change to 500.
I did it according to this method, try it.
4. You can set it directly in MySQL:
#show variables like '%timeout% ';
#show variables like ' max_allowed_packet '
Set global wait_timeout=60000;
#set Global max_allowed_packet = 2*1024*1024

MySQL MySQL lost connection to server during query problem solving method

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.