最近做测试,发现Mysql 过一段时间会无法连接,导致数据库数据不一至,极其郁闷。
使用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
重启生效,需要同时修改这两个参数。
通过上面的步骤还是没有解决问题,通过几天的网上搜索终于又找到的另外一个问题,那就是服务器上安装的jdk版本是1.7的,程序是在1.6下编译的,我把服务重装了JDK1.6之后问题解决了,问题就这么奇怪。
相关推荐
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...
@[Android studio通过jdbc连接mysql基本步骤 以及 遇到的坑“The last packet sent successfully to the server was 0 milliseconds ago”哈哈] 小白第一次发博客哈哈,记录一下这三个晚上来我的悲惨经历以及我成功...
融合多个面上光强信息的混合迭代相位恢复算法
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: ...
BPF
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 ...
Predictable 802.11 Packet Delivery from Wireless Channel Measurements
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 ...
PF: The OpenBSD Packet Filter 官方 PF FAQ
The OpenBSD Packet Filter.pdf The OpenBSD Packet Filter.pdf
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 ...
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...
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...
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 ...
一本介绍linux协议栈数据包处理过程的很好的文档
Practical Packet Analysis will introduce you to the basics of packet analysis, starting with how networks work and how packets travel along the wire. Then you'll move onto navigating packets and using...
Cisco Packet Tracer 5.3 思科路由器交换机模拟软件 Cisco Packet Tracer 5.3 思科路由器交换机模拟软件 Cisco Packet Tracer 5.3 思科路由器交换机模拟软件 Cisco Packet Tracer 5.3 思科路由器交换机模拟软件 ...