The last packet sent successfully to the server was 0 milliseconds ago.
来源:互联网 发布:淘宝带图评价 淘气值 编辑:程序博客网 时间:2024/06/05 15:47
使用Connector/J连接MySQL数据库,程序运行较长时间后就会报以下错误:
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。
其中错误还会提示你修改wait_timeout或是使用Connector/J的autoReconnect属性避免该错误。
后来查了一些资料,才发现遇到这个问题的人还真不少,大部分都是使用连接池方式时才会出现这个问题,短连接应该很难出现这个问题。这个问题的原因:
MySQL服务器默认的“wait_timeout”是28800秒即8小时,意味着如果一个连接的空闲时间超过8个小时,MySQL将自动断开该连接,而连接池却认为该连接还是有效的(因为并未校验连接的有效性),当应用申请使用该连接时,就会导致上面的报错。
解决方法:
(1)使用JDBC URL中使用autoReconnect属性,url添加
&autoReconnect=true&failOverReadOnly=false&maxReconnects=10
(2) 修改MySQL的参数. /etc/my.cnf 添加
[mysqld]wait_timeout=31536000interactive_timeout=31536000
(3)重启mysql
service mysql restart
原因分析:
(1)大量数据访问情况下,mysql connection连接有可能失效
(2)长时间不妨问,connection会失效
0 0
- The last packet sent successfully to the server was 0 milliseconds ago. The
- [Java] 解决异常:“The last packet sent successfully to the server was 0 milliseconds ago.
- The last packet sent successfully to the server was 0 milliseconds ago.
- The last packet sent successfully to the server was 0 milliseconds ago. 的解决办法
- The last packet sent successfully to the server was 0 milliseconds ago.
- The last packet sent successfully to the server was 0 milliseconds ago.
- java mysql The last packet sent successfully to the server was 0 milliseconds ago.
- The last packet sent successfully to the server was 0 milliseconds ago.
- The last packet sent successfully to the server was 0 milliseconds ago.
- 异常The last packet sent successfully to the server was 0 milliseconds ago...
- The last packet sent successfully to the server was 0 milliseconds ago
- The last packet sent successfully to the server was 0 milliseconds ago问题的解决
- Communications link failure:The last packet sent successfully to the server was 0 milliseconds ago.
- mysql 连接出现The last packet sent successfully to the server was 0 milliseconds ago.问题解决
- The last packet sent successfully to the server was 0 milliseconds ago.
- 【MySql】数据库连接异常:The last packet sent successfully to the server was 0 milliseconds ago
- Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received
- The last packet sent successfully to the server was 0 milliseconds ago, The driver has not received
- 线程基本信息
- cad编辑器怎么把cad转换pdf格式
- 课堂练习 二
- bzoj2038莫队模板
- mysql中my.ini配置
- The last packet sent successfully to the server was 0 milliseconds ago.
- 配置环境变量
- MIT的《深度学习》精读(8)
- Android从零单排--常见设计模式
- qml之StackView
- 简单的方法实现文件下载
- ural 2067 Friends and Berries 数学推理
- windbg的!runaway命令
- matlab c# 混合编程笔记