MySQL automatically disconnects all connections every eight hours when the database connection pool is connected to MySQL.

Source: Internet
Author: User
Tags mysql manual

MySQL automatically disconnects all connections every eight hours when the database connection pool is connected to MySQL.

 

I hate this problem recently. In our project, we use our connection pool to connect to the MySQL database. However, every eight hours, the MySQL database will automatically disconnect all connections and the connection pool will become invalid, you need to restart tomcat to make it effective. Ha ha, the server cannot always use "artificial intelligence" to intervene. Later I flipped through the MySQL manual and found that MySQL has a solution, the following is the simplest solution:

 

Add autoreconnect = true when connecting to the database:

 

JDBC: mysql: // localhost: 3306/EMS? Autoreconnect = true & useunicode = true & characterencoding = GBK

 

However, the MySQL manual contains the following:

 

Autoreconnect

DriverProgramShould I try to establish a valid and/or dead connection again? If it is allowed, the driver throws an exception for queries sent over invalid or dead connections (belonging to the current transaction), but when the next query is sent over the connection of the new transaction, will try again.This feature is not recommended because it causes side effects related to session Status and data consistency when the application cannot properly process sqlexceptions.It is designed only for the following scenarios, that is, when you cannot configure an application to properly handle sqlexceptions caused by dead connections and/or invalid connections. As an optional method, you can set the MySQL server variable "wait_timeout" to a high value instead of the default 8 hours.

 

Haha, I don't know what the "side effects" will cause. Will it cause Tomcat to crash ?? Will there be a "data consistency" problem ??

 

To be more secure, add the value of "wait_timeout" and set "28800" to a larger value, so that there is no problem.

 

Note: I am currently using autoreconnect and have not found any problems.

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.