MySQLserverhasgoneaway problem cause _ MySQL

Source: Internet
Author: User
The cause of MySQLserverhasgoneaway is similar today. MySQL is just cold saying: MySQL server has gone away.

You probably browsed it for the following reasons:

One possibility is that the SQL statement sent is too long and exceeds the size of max_allowed_packet. For this reason, you only need to modify my. cnf and increase the value of max_allowed_packet.

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.

Solve MySQL server has gone away

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 desired size)

Max_allowed_packet
The parameter is used to control the maximum length of the 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.