- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
关于 MySQL 的wait_timeout 连接超时问题报错解决方案
Mysql 服务器默认的 “wait_timeout”是 8 小时【也就是默认的值默认是 28800
秒】,也就是说一个 connection 空闲超过 8 个小时,Mysql 将自动断开该
connection,通俗的讲就是一个连接在 8 小时内没有活动,就会自动断开该连接。
wait timeout 的值可以设定,但最多只能是 2147483,不能再大了。也就是约
24.85 天
所以即使你 MySQL 通过 my.ini 在
# The TCP/IP Port the MySQL Server will listen on
port=3306 下面添加
# this is myown dinifition for mysql connection timeout
wait_timeout
interactive_timeout
无论超过最大限度多大的数值,只能被 MySQL 解析为 2147483,2147483 天后你
的程序该出什么错还是什么错,避免不了的
在说这个错误之前先说明我的项目是通过 Hibernate 来进行数据库操作的
关于 MySQL 连接超时问题,估计很多人都遇到过:大致情形都是这样,开发测试
时程序都是正常的,一到第二天就出先莫名错误,比如在我的项目中就是定时任
务执行,每天凌晨一点执行一次,也就是 24 小时每隔 24 小时执行,远远超出了
8 小时
如果你刚好在数据库超时的第一时间内看到日志记录的话那么,第一次超时发生
的错误就是这样的:
ERROR [org.hibernate.util.JDBCExceptionReporter] - Communications link
failure
Last packet sent to the server was 0 ms ago.
如果不是第一次超时后执行,以后每次报错就变成嵌套的错误了,就是下面这样:
ERROR [org.hibernate.util.JDBCExceptionReporter] -
No operations allowed after connection closed.Connection was implicitly
closed due to underlying exception/error:
** BEGIN NESTED EXCEPTION **
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
MESSAGE: The last packet successfully received from the server was86395
milliseconds ago.The last packet sent successfully to the server was 86395
milliseconds 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.
STACKTRACE:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last
packet successfully received from the server was86395 milliseconds
ago.The last packet sent successfully to the server was 86395 milliseconds
ago, which is longer than the server configured value of wait_timeout.
You should consider either expiring and/or testing connection val
文档评论(0)