MySQL server has gone away

Source: Internet
Author: User

1 Problem Description: Client link to MySQL server is broken

2 Causes of problems:

1> MySQL service is down 2> mysql link timeout 3>mysql request link process is active kill    : Query result set exceeds Max_allowed_packet

3 Workaround:

Way One:

Of course is to increase your wait-timeout value, this parameter is set in MY.CNF (under Windows step down is My.ini),
My database load is a little bit larger, so I set the value to 10, (the unit of this value is seconds,
This means that when a database connection does not have any action within 10 seconds, it will be forcibly closed.
I'm not using a permanent link (mysql_pconnect), with Mysql_connect,
You can see the results of this wait-timeout in the MySQL process list (show processlist),
You can set this wait-timeout to larger, such as 300 seconds, hehe, generally speaking 300 seconds enough to use,
In fact you can also not set, MySQL default is 8 hours. The situation is determined by your server and site.

Way two:

This is also my personal view of the best method, that is, check the status of MySQL link, so that it relink.
Maybe we all know that there is mysql_ping such a function, in a lot of information that this mysql_ping API will check whether the database is linked,
If it is disconnected, it will try to reconnect, but in my test I found that it is not the case, it is conditional,
Must pass the relevant parameter through Mysql_options this C API, let MySQL have the option of Disconnecting automatic link (mysql default is not automatically connected),
But I test found PHP in the MySQL API does not carry this function, you re-edit MySQL bar, hehe.
But mysql_ping this function is finally able to use, but in which there is a small operation skills:
This is one of the functions in the middle of my database operations class

MySQL server 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.