MySQL server has gone away cause analysis and solutions

Source: Internet
Author: User

1, applications (such as PHP) for a long time to execute the batch of MySQL statements. The most common is acquisition or new and old data conversion.
Solution:
Add or modify the following two variables in the my.cnf file:
wait_timeout=2880000
Interactive_timeout = 2880000
A specific description of two variables can be Google or read the Official Handbook. If you cannot modify MY.CNF, you can set up client_interactive when you connect to the database, for example:
sql = "Set interactive_timeout=24*3600";
Mysql_real_query (...)

2, execute a SQL, but the SQL statement is too large or the statement contains a BLOB or Longblob field. For example, the processing of image data
Solution:
Add or modify the following variables in the my.cnf file:
Max_allowed_packet = 10M (You can also set the size you want)
The function of the Max_allowed_packet parameter is to control the maximum length of its communication buffer.


There is also a possibility for some reason to timeout, such as the use of singleton in the process of getting a database connection, although the database is connected multiple times, but in fact, the same connection is used, and a two times in the program of the operation of the database Time exceeded wait_timeout (show Status to see this setting), there may be a problem. The simplest way is to change the wait_timeout, of course, you can also in the program occasionally mysql_ping (), so that MySQL knows it is not a person in the fight.

The "MySQL (best combination of PHP) server has gone away" error occurs when you import a backup using MySQL (the best combination of PHP), possibly because some of the INSERT statements are larger than the MySQL ( The best combination of PHP with the size of the buffer currently set.

Solutions

1. When using phpMyAdmin to back up MySQL (the best combination of PHP), select only

Data:
Full insert
Extended Insert

Expand insert do not tick

2. Use MySQL (best combination of PHP) dump backup without adding--opt

This will only generate a complete INSERT statement, and there will be no error during import.

3. Modify My.ini

Open My.ini and find the [MySQL (best combination of PHP) d] line, add the following

[The best combination of MySQL (and PHP) d]

#扩大缓冲区
max_allowed_packet=32m
After saving, restart MySQL (the best combination with PHP)

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.