Connection timeout after MySQL is idle for 8 hours

Source: Internet
Author: User

ApplicationProgramEstablish a connection with the database. If the application does not access the database for more than 8 hours, the database will be disconnected. Then, an exception will be thrown during the next access, as shown below:

Communications link failure due
Underlying exception:

** Begin nested exception **  

Java. Io. eofexception

Stacktrace:

Java. Io. eofexception
At com. MySQL. JDBC. mysqlio. readfully (mysqlio. Java: 1913 )
At com. MySQL. JDBC. mysqlio. reuseandreadpacket (mysqlio. Java: 2304 )
At com. MySQL. JDBC. mysqlio. checkerrorpacket (mysqlio. Java: 2803 )
At com. MySQL. JDBC. mysqlio. sendcommand (mysqlio. Java: 1573 )
...

OnlineArticleMost of the solutions are to add the "autoreconnect = true" option to the database connection string. However, this is only valid for versions earlier than MySQL 4. This cannot be done in the latest MySQL. In fact, it is very easy to solve this problem, that is, to modify the MySQL startup parameters. By default, the timeout time of MySQL is 28800 seconds, that is, 8 hours. If you add a value of 0, the problem is solved.

Mysqld -- Interactive_timeout = 288000

You can also add this parameter to the "My. ini" file.

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.