Solution for "Lost connection to MySQL server during query" error when querying in MySQL

Source: Internet
Author: User
Tags error code php database

First, the problem description:

MySQL database query, encountered the following error message:

Second, reason analysis:

Dw_user table data volume is large, direct query speed is slow, easy to "card dead", resulting in automatic database connection timeout ....

Third, the solution:

Scenario 1. Add a line under MySQL configuration file [Myslqd] to set skip-name-resolve. The MySQL service needs to be restarted.

Scenario 2: Adding an IP and hostname mapping in the Hosts file [this way does not restart]

For example: In the Hosts file, add:

127.0. 0.1 localhost  

Other online methods:

1. At the code level, you need to add roughly the following code to your PHP database connection.

if (   in_array(mysql_errnoarray(2006))) {           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 is  600 seconds   = y Maximum allowable data amount  

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 -: Lost Connection toMySQL Server during query error code:1153 -Got a packet bigger than'Max_allowed_packet'bytes Solution: Modify the Mysql.ini (online is said to be this file, find n long finally know where, my directory is in the D:\MySQL_Data\MySQL Server5.5in the Mysql_data folder) file add the following code to Max_allowed_packet=500M Modify D:\MySQL\MySQL Server If it is not possible5.5\my-the Max_allowed_packet in Huge.ini.=16M Change 16 to 500 I did it according to this method, try it.


4. You can set it directly in MySQL:

 like ' %timeout% ' ;    like ' Max_allowed_packet '  set global wait_timeout=60000;  #Set=2*1024x768*1024x768  

Solution for "Lost connection to MySQL server during query" error when querying in MySQL

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: info-contact@alibabacloud.com 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.