mysql 8小时问题的解决方法

转发: 别看是英文 ,写的很好 ,才转

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 was 58129 seconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and / or testing connection validity before use in your application, increasing the server 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 operations), mysql will automatically disconnect to restart the tomcat.

The solution:

One. If you do not hibernate, then adding in the connection url parameter: autoReconnect = true

jdbc.url = jdbc: mysql: / / ipaddress: 3306/database? autoReconnect = true & autoReconnectForPools = true

Two. 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 will run a long time after the reports the following error:

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

One error will 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 connection pooling will appear this way, short connection should be very difficult to have 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 will automatically disconnect the connection, and connection pool is that the connection is still valid (because the school did not test the effectiveness of the connection), when the application when applying for the connection, it will lead to the above error.

1. In accordance with the error prompt, you can use the autoReconnect JDBC URL attribute, the actual test used autoReconnect = true & failOverReadOnly = false, but did not work, use the 5.1 version, you may really like the Internet before talking about only 4 version of the force.

2. No way, can only modify the parameters of the MySQL, wait_timeout a maximum of 31536000 that is 1 year, add in my.cnf:

[Mysqld]

wait_timeout = 31536000

interactive_timeout = 31536000

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

最新文章

  1. Mybatis 拦截器
  2. svn无法创建分支的解决方法
  3. 工厂模式(Factory Patter)
  4. 014--VS2013 C++ c++定时动画
  5. ubuntu npm 私有库搭建 (npmjs.org 官方版本)
  6. php对象与数组互转
  7. Bloom Filter概念和原理
  8. php自定义函数求取平方根
  9. vue的ajax请求之axios
  10. angular2 ----字符串、对象、base64 之间的转换
  11. Kubernetes dashboard安装
  12. K2在Gartner 2017 iBPMS魔力象限报告中上升为“挑战者”
  13. C# 流水号生成器开发
  14. 机器学习: K-means 聚类
  15. 浏览器标识ua
  16. CoderForce 140C-New Year Snowmen(贪心)
  17. MySQL架构与引擎初识
  18. tooltips &amp; click copy
  19. python进行机器学习(五)之模型打分
  20. 经常使用的 WEB server

热门文章

  1. Maven使用-创建一个Web项目
  2. 相关Jquery Validator采用
  3. Java中导入、导出Excel
  4. unity3d 各功能的运行秩序,打回来,订购,的次数
  5. c# 16进制显示转化
  6. How to pause the game in Uniy3D
  7. ADT后windows菜单未找到Android SDK Manager和Android Virtual Device Manager该解决方案的选择
  8. dom 规划(html和xml)
  9. DDD领域驱动设计初探
  10. SWI-Prolog