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.

myql_链接丢失异常_mybaits _等框架_报错_The last packet successfully的更多相关文章

  1. 【干货】YUM安装PHP 7版本后,增加phalcon框架的报错解决

    目录 1.yum安装php 7.x版本,此处部署7.3版本 2.安装phalcon框架 2.1.PHP版本依赖关系 2.2.编译phalcon扩展模块 2.3.增加扩展文件 3.部署phalcon遇到 ...

  2. spring mvc 框架启动报错:nested exception is java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal 解决办法

    今天准备将以前自己搭建的一个框架拿出来用一下,结果发现启动报错:nested exception is java.lang.NoClassDefFoundError: org/w3c/dom/Elem ...

  3. 关于laravel框架分页报错的问题

    因为laravel框架有自己的分页封装,所以与其他框架相比laravel框架的分页的实现要方便的多 只要分别在php脚本与视图中使用 $data=DB::table('index_pic')-> ...

  4. 日志框架整合报错Class path contains multiple SLF4J bindings.

    在进行SSM框架的日志框架统一管理时,报错Class path contains multiple SLF4J bindings 如下图 意思是类路径下包含重复的SLF4J绑定,然后给出了重复的两个全 ...

  5. 2 _ 基本框架 _ 检测VMX环境

    VT 是先开为大,谁先开谁上层,谁上层 谁权限大. 1 判断是否支持 VMX intel 白皮书 第3卷 传入 参数eax =1, 返回值 ecx 的第5位 = 1 则 surpported VMX. ...

  6. springmvc+thymeleaf搭建框架启动报错

    最近项目开发需要用到thymeleaf前端界面模板引擎,所以提前了解学习一下,但是在框架搭建好了之后启动tomcat一直提示如下错误: org.springframework.beans.factor ...

  7. iOS AFNetworking 2.6.0框架导入报错解决方法

    最近手动导入AFNetworking 2.6.0框架时发现Xcode报如下3个错误: 1. Use of undeclared identifier ‘kSecFormatUnknown‘ 2. Us ...

  8. python基于Django框架编译报错“django.core.exceptions.ImproperlyConfigured”的解决办法?

    下面是我具体遇到的问题和解决方法: 错误详细信息: django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_IND ...

  9. RocketMQ_问题_启动控制台console报错,connect to <null> failed

    配置如图所示: 问题如图所示: 明明配置了nameserver参数为啥还是connect to null呢? 我的rocketmq部署在CentOS7虚拟机上,原来是没关闭防火墙,执行:systemc ...

随机推荐

  1. Web静态和动态项目委托代理基于面向方面编程AOP

    本来每天更新,我一般喜欢晚上十二点的时候发文章,结果是不是愚人节?校内网也将是非常有趣,破,把我给打. ..好吧-从今天开始的话题AOP.AOP太重要了,所以把第二篇文章谈论这个话题,AOP它是Spr ...

  2. 关于scope_identity()与 @@IDENTITY

    原文:关于scope_identity()与 @@IDENTITY 参考:https://msdn.microsoft.com/zh-cn/library/ms190315.aspx scope_id ...

  3. 每天进步一点点之SQL 获取表中某个时间字段离当前时间最近的几条

    实际中用到的SQL: select * from (select top 3 Id, case when startSignup>GETDATE() then '敬请期待' when (star ...

  4. async And await异步编程活用基础

    原文:async And await异步编程活用基础 好久没写博客了,时隔5个月,奉上一篇精心准备的文章,希望大家能有所收获,对async 和 await 的理解有更深一层的理解. async 和 a ...

  5. 使用commons-fileupload进行上传

    须要使用的包 这两个包在Apache官网上能够下载得到 commons-fileupload-1.3.1.jar是Apache的一个开源项目.废话不说直接说吧 前段页面 <form action ...

  6. Spring3 MVC请求参数获取的几种场景

    访问/aaa/bbb所对应的@Controller @RequestMapping("/aaa")//类级别,可以不需要,如果要了,下面所有的请求路径前都需要加入/aaa publ ...

  7. 如何在Dreamweaver中使用zen coding

    在我发表上一篇<Zen Coding: 一种快速编写HTML/CSS代码的方法>之后,有网友表示不知道怎么在Dreamweaver上使用zen coding插件.OK,今天我就写一篇详细的 ...

  8. 解决UnicodeEncodeError: 'ascii' codec can't encode characters in position 问题(转)

    UnicodeEncodeError: 'ascii' codec can't encode characters in position 8-11: ordinal not in range(128 ...

  9. 性能优化——统计信息——SQLServer自动更新和自动创建统计信息选项

    原文:性能优化--统计信息--SQLServer自动更新和自动创建统计信息选项 原文译自:http://www.mssqltips.com/sqlservertip/2766/sql-server-a ...

  10. Java拾遗(一):浅析Java子类和父类的实例化顺序 及 陷阱

    本文主要介绍Java里经常使用的子类和父类的变量实例化顺序及陷阱,并结合一个Android实例来探讨此问题.日后编程中应尽量避免此陷阱. 首先看以下一段代码: 定义一个虚类Server.java pa ...