MySQL has gone away

Source: Internet
Author: User

The problem with MySQL Error: (2006, ' MySQL server has gone away ') means that the link between the client and MySQL server is broken.

The reason for this is generally that the SQL operation takes too long, or that the data being transferred is too large (for example, using INSERT ...) the statement of values is too long, which can be avoided by modifying the configuration parameters of the max_allowed_packed, or by inserting the data in batches in the program.

There are many reasons for this problem, which is summarized under the online analysis:

Reason one. MySQL service is down.

A simple way to determine if this is the cause is to go to the MySQL console and see how long MySQL is running

Mysql> show global status like ' uptime '; +---------------+---------+| variable_name | Value   |+---------------+---------+| Uptime        | 3414707 |+---------------+---------+

  

1 row in set or check MySQL error log to see if there is any information to restart

If the uptime value is large, it indicates that the MySQL service has been running for a long time. Indicates that the service has not been restarted recently.
If the log does not have relevant information, also the table name MySQL service has not been restarted recently, you can continue to check the following several things.

Cause two. MySQL Connection timed out

That is, a MySQL long connection has not been initiated for a long time, reached the server side timeout, was forcibly shut down by the server.
After this connection initiated the query, it will error server has gone away
(Most PHP scripts fall into this category)

Mysql> show global variables like '%timeout '; +----------------------------+----------+| Variable_name              | Value    |+----------------------------+----------+| connect_timeout            | |       | delayed_insert_timeout     | |      | innodb_lock_wait_timeout | | | |       innodb_rollback_on_timeout | OFF      | | interactive_timeout |        28800 |    | lock_wait_timeout          | 31536000 | | net_read_timeout           | 30       | | | net_write_timeout          | |       | slave_net_timeout          | 3600     | | wait_timeout               | 28800    |+----------------------------+--- -------+10 rows in Set

  

Wait_timeout is 28,800 seconds, that is, the MySQL link is automatically closed after 28,800 seconds of no operation

Cause three. MySQL Request link process is active kill

This is similar to the reason two, just one person is a MySQL own action

Mysql> show global status like ' Com_kill '; +---------------+-------+| variable_name | Value |+---------------+-------+| Com_kill      |    |+---------------+-------+1 row in Set

  

Cause four. Your SQL statement was too large.

This error can also occur when the result set of the query exceeds Max_allowed_packet. The positioning method is to play the relevant error statement.

Export to a file using select * into outfile to see if the file size exceeds max_allowed_packet, and if it is exceeded, you need to adjust the parameters or refine the statement.

Mysql> show global variables like ' max_allowed_packet '; +--------------------+---------+| Variable_name      | Value   |+--------------------+---------+| max_allowed_packet | 1048576 |+--------------------+---------+1 row in Set (0.00 sec)


Modify Parameters:

Mysql> set global max_allowed_packet=1024*1024*16;mysql> show global variables like ' max_allowed_packet '; +------ --------------+----------+| Variable_name      | Value    |+--------------------+----------+| max_allowed_packet | 16777216 |+--------------------+----------+1 row In Set (0.00 sec)

  

The situation encountered;

When using MySQL statements, errors are always performed, but there is no problem checking the statements;

View error MySQL server has gone away

From the Internet to find these kinds of situations, according to the situation analysis, I set the problem, belongs to the situation 4

Executes a SQL, but the SQL statement is too large or contains a BLOB or LONGBLOB field in the statement. 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 Max_allowed_packet parameter is used to control the maximum length of its communication buffer.

Link extension:

Http://www.jb51.net/article/23781.htm

MySQL has gone away

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.