最近做测试,发现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之后问题解决了,问题就这么奇怪。
相关推荐
本次异常的具体描述为:“Communications link failure due to underlying exception: **BEGINNESTED EXCEPTION** java.io.EOFException STACK TRACE: java.io.EOFException at com.mysql.jdbc.MysqlIO.readFully...
@[Android studio通过jdbc连接mysql基本步骤 以及 遇到的坑“The last packet sent successfully to the server was 0 milliseconds ago”哈哈] 小白第一次发博客哈哈,记录一下这三个晚上来我的悲惨经历以及我成功...
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...
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 ...
【MySQL与JDBC1】是关于使用MySQL数据库和Java JDBC(Java Database Connectivity)进行数据库操作的基础教程。在本文中,我们将深入探讨如何在MySQL中执行常见的数据库管理任务,包括创建和删除数据库、操作数据库...
融合多个面上光强信息的混合迭代相位恢复算法
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 ...
### BSD Packet Filter (BPF): 新架构下的用户级数据包捕获 #### 概述 本文档探讨了**BSD Packet Filter (BPF)**——一种新型的用户级数据包捕获架构,该架构由Steven McCanne和Van Jacobson在1992年提出,并计划...
LinuxMint加入域时的错误解决方案,包括:DNS_ERROR_BAD_PACKET、ERROR_GEN_FAILURE 0x00000001f、Unable to find ssh binary
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 84,371,623 milliseconds ago. The last packet sent successfully to the server was 78,...
思科CCNA学习笔记 思科CCNA学习笔记是网络工程师的必备知识,涵盖了计算机网络的基本概念、OSI与TCP/IP协议框架、IP报文传输过程、传输层功能、TCP与UDP对比等内容。以下是该笔记的详细知识点: 一、OSI与TCP/IP...
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 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 ...
This is the release notice for the PCnet Magic Packet(TM) Utility Revision 1.00 software. All files are in DOS FAT format. AMD抯 Magic Packet utility is a convenient tool for system administrators ...
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...
本文档是一份关于4G LTE技术的详细学习笔记,它从技术演进、空口协议栈、关键技术、主要业务流程等多个维度对LTE技术进行了全面的剖析。下面将基于提供的文档内容,详细阐述这些知识点。 一、LTE技术的演进 LTE技术...