MySQL server has gone away Cause Analysis and Solution

Source: Internet
Author: User

This MySQL server has gone away was suddenly encountered during development today. The analysis may be that the SQL statement sent is too long and exceeds the size of max_allowed_packet. If this is the reason, you only need to modify my. cnf: Increase the value of max_allowed_packet.

1. applications (such as PHP) execute MYSQL statements in batches for a long time. The most common is collection or conversion of New and Old data.
Solution:
Add or modify the following two variables in the my. cnf file:
Wait_timeout = 2880000
Interactive_timeout = 2880000
For details about the two variables, refer to google or the official manual. If you cannot modify my. cnf, you can set CLIENT_INTERACTIVE when connecting to the database. For example:
SQL = "set interactive_timeout = 24*3600 ";
Mysql_real_query (...)

2. Execute an SQL statement, but the SQL statement is too large or the statement contains BLOB or longblob fields. For example, processing image data
Solution:
Add or modify the following variables in the my. cnf file:
Max_allowed_packet = 10 M (you can also set the size you need)
The max_allowed_packet parameter is used to control the maximum length of the Communication buffer.


There is another possibility that timeout may be caused due to some reasons. For example, Singleton is used in the program to obtain the database connection. Although the program connects to the database multiple times, it actually uses the same connection, in addition, if the interval between two database operations in the program exceeds wait_timeout (this setting can be seen in show status), a problem may occur. The simplest way to deal with it is to increase wait_timeout. Of course, you can also use mysql_ping () in the program from time to time, so that MySQL knows that it is not a battle.

 

The "MySQL (best combination with PHP)" server has gone away "error occurs when you use the MySQL (best combination with PHP) command line to import the backup, this may be because the size of some insert statements exceeds the buffer size currently set by MySQL (the best combination with PHP.

Solution

1. When using phpmyadmin to back up MySQL (the best combination with PHP), select

Data:
Complete insert
Extended insert

Do not select extension insert

2. Do not add -- opt when using MySQL (the best combination with PHP) dump backup.

In this way, only the complete insert statement will be generated, and no errors will occur during the import.

3. modify my. ini

Open my. ini and find [MySQL (the best combination with PHP) d]. Add

[MySQL (the best combination with PHP) d]

# Expanding the Buffer Zone
Max_allowed_packet = 32 M
After saving, restart MySQL (the best combination with PHP)

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.