MySQL 8-hour problem solving method

Source: Internet
Author: User

Use Hibernate + MYSQL database development, link timeout problem:

Com.mysql.jdbc.CommunicationsException:The last packet successfully received from the server was58129 seconds ago. The last packet sent successfully to the server were 58129 seconds ago, which is longer than the server configured value of ' Wait_timeout '. Should consider either expiring and/or testing connection validity before use in your application, increasing the SE RVer configured values for client timeouts, or using the-connector/j connection property ' AutoReConnect = True ' to avoid This problem.  

Checked and the original problem is the MySQL timeout if the connection idle for 8 hours (8 hours, no database Operati ONS), MySQL would automatically disconnect to restart the tomcat.  

The solution:

One . If you don't hibernate, then adding in the connection URL Parameter:autoreconnect = True

Jdbc.url = jdbc:mysql://ipaddress:3306/database? autoreconnect = True & autoreconnectforpools = True

Both . With hibernate, then add the following attributes:
<property name= "Connection.autoreconnect" > True </property>
<property name= "Connection.autoreconnectforpools" > True </property>
<property name= "connection.is-connection-validation-required" > True </property>

iii. If still using C3P0 connection pool:
<property name= "Hibernate.c3p0.acquire_increment" > 1 </property>
<property name= "Hibernate.c3p0.idle_test_period" > 0 </property>
<property name= "Hibernate.c3p0.timeout" > 0 </property>
<property name= "Hibernate.c3p0.validate" > True </property>

Iv. The worst solution

Using the connector/j MySQL database connection, the program would run a long time after the reports the following ER ROR:

Communications link failure, the last packet successfully received by the server was * * * * millisecond ago. The last packet successfully sent to the server was * * * * millisecond ago.  

One error would prompt you to change wait_timeout or use the connector/j's AutoReConnect property to avoid the error.  

Then check out some information, only to find people who experience this problem quite a lot, mostly when using Connec tion pooling'll appear this-the-a-, short connection should is very difficult to has this problem. The cause of the problem:

MySQL Server Default "Wait_timeout" is 28,800 seconds or 8 hours, means that if a connection idle time exceed 8 hours, MySQL would automatically disconnect the connection, and connection pool is that the connection is still valid (because th E School did not test the effectiveness of the connection), when the application is applying for the connection, it would Leads to the above error.  

1. In accordance with the error prompt, you can use the AutoReConnect JDBC URL attribute, the actual test used Autorec Onnect = True & failoverreadonly = False, but do not work, with the 5.1 version, you could really like the Internet befo Re talking about only 4 version of the Force.  

2. No, can only modify the parameters of the MySQL, wait_timeout a maximum of 31536000, which is 1 year, add in My.c NF:

[Mysqld]

wait_timeout = 31536000

interactive_timeout = 31536000

Restart effect, you need to modify these, parameters simultaneously.

MySQL 8-hour problem solving method

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.