Troubleshoot MySQL server has gone away

Source: Internet
Author: User

Today encountered a similar scenario, MySQL is just coldly said: MySQL server has gone away.

I have probably browsed for a few reasons, mainly because of the following:

One possibility is that the SQL statement sent is too long to exceed the size of the max_allowed_packet, and if this is the reason, you just need to modify the MY.CNF to enlarge the Max_allowed_packet value.

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.

Troubleshoot MySQL server has gone away

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)

max_allowed_packetThe function of a parameter is to control the maximum length of its communication buffer.

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.