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.