jdbc 连接mysql Communications link failure的解决办法
使用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将自动断开该连接,而连接池却认为该连接还是有效的(因为并未校验连接的有效性),当应用申请使用该连接时,就会导致上面的报错。
修改MySQL的参数,wait_timeout最大为31536000即1年,在my.conf中加入:
[mysqld] wait_timeout= interactive_timeout=
重启生效,需要同时修改这两个参数。
jdbc 连接mysql Communications link failure的解决办法的更多相关文章
- 【MySQL】JDBC连接MySQL的一些问题以及解决办法
[MySQL]JDBC连接MySQL的一些问题以及解决办法 http://blog.csdn.net/baofeidyz/article/details/52017047
- Communications link failure的解决办法
使用Connector/J连接MySQL数据库,程序运行较长时间后就会报以下错误: Communications link failure,The last packet successfully r ...
- 解决MySQL连接超时Communications link failure due to underlying exception
最近在用一个MySQL的Java连接池的过程中,连接一晚上不释放,第二天就会造成超时的错误,查了一下原因,原来是因为MySQL默认的空闲等待时间是8个小时,一旦空闲超过8个小时,就会抛出异常.异常文本 ...
- 【Azure 应用服务】App Service 无法连接到Azure MySQL服务,报错:com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
问题描述 App Service使用jdbc连接MySQL服务,出现大量的 Communications link failure: com.mysql.cj.jdbc.exceptions.Com ...
- 解决:com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure(真实有效)
数据库连接失败 一.例如我在SpringBoot项目中使用了阿里的数据库连接池Driud. 有次在启动的时候,会报这样的错: Caused by: com.mysql.cj.exceptions.CJ ...
- Mysql Communications link failure 问题的解决
问题现象 com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last p ...
- Communications link failure异常解决
一,异常现象 com.bill99.inf.ibatis.DBException: queryForList error::sqlId=orgOrderAssetsMapping.queryModel ...
- mysql Communications link failure Last packet sent to the server was X ms ago
想必大家在用MySQL时都会遇到连接超时的问题,如下图所示: 就是这个异常(com.mysql.jdbc.exceptions.jdbc4.Communication***ception:Commun ...
- mysql Communications link failure,C3p0的参数详解
MySQL默认一个连接空闲8小时候就会自动断开,而这时程序以为连接还能使用,然后在使用的时候就会出现Communications link failure异常. 这时需要进行两步设置,有时候只设置My ...
随机推荐
- Combination Sum —— LeetCode
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...
- Minimum Size Subarray Sum —— LeetCode
Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...
- Hat's Fibonacci(大数问题)
#include <iostream>#include <stdio.h>#include <string.h>using namespace std;int a[ ...
- LeetCode (85): Maximal Rectangle [含84题分析]
链接: https://leetcode.com/problems/maximal-rectangle/ [描述] Given a 2D binary matrix filled with '0's ...
- eclipse 导入项目时候java版本不一致问题
最近导入一个java项目,发现我安装的java版本是1.8.0_111,而项目的版本是1.8.0_101,当然不想重新再安装旧的java版本,于是就在网上找了解决方法. 在项目的library中右击, ...
- Apache Kylin
日前,eBay公司隆重宣布已经正式向开源业界推出分布式分析引擎:Kylin(http://kylin.io).作为一套旨在对Hadoop环境下分析流程进行加速.且能够与SQL兼容性工具顺利协作的解决方 ...
- lantern蓝灯导致IE和一些软件不能上网解决方法
@echo offREG DELETE "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Setti ...
- js提交前弹出提示框
<form target="_blank" name="f1" method="post" action="sub2.php ...
- 【算法与数据结构】在n个数中取第k大的数(基础篇)
(转载请注明出处:http://blog.csdn.net/buptgshengod) 题目介绍 在n个数中取第k大的数(基础篇),之所以叫基础篇是因为还有很多更高级的算法,这些 ...
- 如何提高Lucene构建索引的速度
如何提高Lucene构建索引的速度 hans(汉斯) 2013-01-27 10:12 对于Lucene>=2.3:IndexWriter可以自行根据内存使用来释放缓存.调用writer.set ...