Resolution: mysqlconnection timeout after idle for 8 hours _ MySQL

Source: Internet
Author: User
Mysql8-hour idle connection timeout Q: How can I solve the problem of mysql8-hour idle connection timeout? A: If an application establishes a connection with a database for more than eight hours, the database will be disconnected if the application does not access the database. In this case, an exception will be thrown during the next access. The exception is as follows: Communicationsl

Connection timeout after mysql is idle for 8 hours

Q:How can I solve the problem of connection timeout after mysql is idle for 8 hours?

A:When an application establishes a connection with a database, if the connection lasts for more than 8 hours, the application will not access the database, and the database will be disconnected. Then, an exception is thrown when you access the service again. The exception is as follows:

     Communications link failure due tounderlying exception: ** BEGIN NESTED EXCEPTION ** java.io.EOFExceptionSTACKTRACE: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)...

The general solution is to add the "autoReconnect = true" option to the database connection string. However, this is only valid for versions earlier than MySQL 4. It is invalid in the latest mysql. In fact, there is also a simple way to solve this problem, that is, to modify the mysql startup parameters. By default, the timeout time of mysql is 28800 seconds, which is exactly 8 hours. you can add a value of 0.

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

     mysqld-nt --default-table-type=innodb --interactive_timeout=288000
Related Article

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.