使用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属性,实际测试时使用了autoReconnect=true&failOverReadOnly=false,不过并未起作用,使用的是5.1版本,可能真像网上所说的只对4之前的版本有效。
2.没办法,只能修改MySQL的参数了,wait_timeout最大为31536000即1年,在my.cnf中加入:
[mysqld]
wait_timeout=31536000
interactive_timeout=31536000
重启生效,需要同时修改这两个参数。
分享到:
相关推荐
@[Android studio通过jdbc连接mysql基本步骤 以及 遇到的坑“The last packet sent successfully to the server was 0 milliseconds ago”哈哈] 小白第一次发博客哈哈,记录一下这三个晚上来我的悲惨经历以及我成功...
2.查看数据库表创建完成后,我们可以查看数据库表show tables 2.修改表记录2.1 不带条件的update 表名 set 字段名=值, 字段名=值,
Cause com.mysql.jdbc.exceptions.jdbc4.CommunicationsException The last packet successfully received from the server was 47,795,922 milliseconds ago. The last packet sent successfully to the server was...
融合多个面上光强信息的混合迭代相位恢复算法
23. The five layers in the Internet protocol stack are – from top to bottom – the application layer, the transport layer, the network layer, the link layer, and the physical layer. The principal ...
The last packet successfully received from the server was 56,201,339 milliseconds ago. The last packet sent successfully to the server was 56,201,339 milliseconds ago. is longer than the server ...
BPF
In addition, the book covers additional topics for memory management and congestion avoidance, used to extract higher performance from the interconnection network. Table of Contents Part I: ...
PF: The OpenBSD Packet Filter 官方 PF FAQ
Predictable 802.11 Packet Delivery from Wireless Channel Measurements
The OpenBSD Packet Filter.pdf The OpenBSD Packet Filter.pdf
compose up 请注意,第一次运行时,您可能会看到: mvw_flyway | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. (Caused by...
It’s easy to capture packets with Wireshark, the world’s most popular network sniffer, whether off the wire or from the air. But how do you use those packets to understand what’s happening on your ...
The Practical Packet Analysis course is perfect for beginners to intermediate analysts, but seasoned pros will probably learn a few useful techniques too. Whether you’ve never capture packets before ...
一本介绍linux协议栈数据包处理过程的很好的文档
The "ptsaplayer.dll" in the .zip package is the patch to fix the issue that Packet Tracer 7.2.2's PTSAPlayer plugin does not work on Windows 7. Apply the patch will fix the issue. Only users using...
The "ptsaplayer.dll" in the .zip package is the patch to fix the issue that Packet Tracer 7.2.2's PTSAPlayer plugin does not work on Windows 7. Apply the patch will fix the issue. Only users using...
Cisco Packet Tracer 7.2.2 removes the Java dependence and makes it easier to use Packet Tracer Skills Assessment (PTSA) and Packet Tracer Media Objects (PTMO) : After installing Packet Tracer 7.2.2...
This paper presents a new packet routing scheme which allows a vehicle to discover the existence of a gateway to the Internet and to send/receive packets to/from the gateway via multihop ...
The design presented here is based on the input of numerous professionals from the pointing device manufacturing and Windows soft¬ware development industries. In this document, the words "tablet" ...