com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 126,421,823 milliseconds ago. The last packet sent successfully to the server was 126,421,823 milliseconds ago. 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.
java
解决办法:mysql
修改mysql配置文件,更改链接失效时间linux
mysql﹥sql
mysql﹥ show global variables like ‘wait_timeout’;数据库
+—————+———+windows
| Variable_name | Value |tomcat
+—————+———+app
| wait_timeout | 28800 |ide
+—————+———+测试
1 row in set (0.00 sec)
28800 seconds,也就是8小时。
若是在wait_timeout秒期间内,数据库链接(java.sql.Connection)一直处于等待状态,mysql5就将该链接关闭。这时,你的Java应用的链接池仍然合法地持有该链接的引用。当用该链接来进行数据库操做时,就碰到上述错误。这解释了为何个人程序次日不能登陆 的问题。
你可能会想到在tomcat的数据源配置中有没有办法解决?的确,在jdbc链接url的配置中,你能够附上“autoReconnect=true”,但这仅对mysql5之前的版本起做用。增长“validation query”彷佛也无济于事。
本人以为最简单的办法,就是对症下药:既然问题是由mysql5的全局变量wait_timeout的缺省值过小引发的,咱们将其改大就行了。
查看mysql5的手册,发现对wait_timeout的最大值分别是24天/365天(windows/linux)。以windows为 例,假设咱们要将其设为21天,咱们只要修改mysql5的配置文件“my.ini”(mysql5 installation dir),增长一行:wait_timeout=1814400
须要从新启动mysql5。
linux系统配置文件:/etc/my.cnf
测试显示问题解决了。
也能够直接设置
mysql修改wait_timeout
mysql mysql> show global variables like ‘wait_timeout’;
其默认值为8小时
mysql的一个connection空闲时间超过8小时,mysql会自动断开该链接。
1.修改配置
vi /etc/my.cnf
[mysqld] wait_timeout=10
# /etc/init.d/mysql restart
2.直接用sql命令行修改 mysql> set global wait_timeout=604800;
除了wait_timeout,还有一个’interactive_timeout’
一样能够执行SHOW GLOBAL VARIABLES LIKE ‘interactive_timeout’;来查询 执行set global interactive_timeout=604800;来设置