使用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.cnf中加入:

my.cnf位置在MySQL安装目录下:

[mysqld]

    wait_timeout=31536000interactive_timeout=31536000

重启mysql服务生效,需要同时修改这两个参数。

Communications link failure的解决办法相关推荐

  1. 连接数据库报错com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure的解决方法

    控制台报错 Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure com. ...

  2. 解决——》CommunicationsException:Communications link failure

    推荐链接:     总结-->[Java]     总结-->[Mysql]     总结-->[Spring]     总结-->[SpringBoot]     总结--& ...

  3. Communications link failure 解决方法 !!!

    Communications link failure 解决方法 最近在使用mybatis逆向生成的时候遇到了link failure的问题, 这里记录解决方法 文章目录 Communications ...

  4. Communications link failure解决

    启动程序时报错Communications link failure The last packet sent successfully to the server was 0 millisecond ...

  5. [08S01] Communications link failure报错解决

    通过ide连接数据库或者 启动java项目的时候数据库连接不上报错 [08S01] Communications link failure The last packet sent successfu ...

  6. Connection timed out: connect; Communications link failure

    今天过来启动自己的项目出现如下的问题: Communications link failure The last packet sent successfully to the server was ...

  7. Communications link failure错误(亲测有效)

    当时我的报了这个错误,我就从网上搜了解决这类问题的办法,找到的大多数是说:MySQL服务器默认的"wait_timeout"是8小时,数据库超过8小时没用,链接超时了. 让修改这两 ...

  8. 连接mysql异常Communications link failure

    连接mysql 数据库的时候出现这个异常Communications link failure,原因:如果在wait_timeout秒期间内,数据库连接(java.sql.Connection)一直处 ...

  9. 【数据库问题】[08S01] Communications link failure

    [08S01] Communications link failure The last packet sent successfully to the server was 0 millisecon ...

最新文章

  1. 聊聊flink的AscendingTimestampExtractor
  2. 蓝牙杂散超标_杂散发射
  3. [CSS]滤镜用法(1)
  4. 电脑公司win11旗舰版32位镜像v2021.07
  5. redis主从配置及无法连接处理
  6. 验证身份证合法性的js
  7. php岗位专业技能,PHP简历专业技能怎么写
  8. Cannot change version of project facet Dynamic Web Module to 2.5解决方案
  9. 发家致富:爬取双色球信息并统计
  10. 使用python代码调用三汇语音卡硬件拨打电话
  11. 修改Office 2016安装路径的方法
  12. JavaEE中的依赖性——依赖查找
  13. 惠普HP Deskjet 1180c 打印机驱动
  14. 计算机自动弹回桌面,win10玩无主之地2自动返回桌面怎么办
  15. 微信聊天服务器端口号怎么查,如何查看服务的端口号
  16. 数字电路课设_电子抢答器
  17. 西湖大学张岳老师实验室招收博士、研究助理、实习生啦~
  18. 学术沙龙-写好综述-读书笔记分享和讨论
  19. 就算砸下1300亿造车,苹果颠覆行业也有点难
  20. Flutter Icons 内置图标库,全套Material图标

热门文章

  1. 基于iOS平台配置免费离线语音识别功能-OpenEars
  2. 关于MQTT协议实现消息推送系统
  3. 电子与信息学报的图片格式
  4. manjaro时间不对,恢复正确时间
  5. 山东大学2019计算机考研分数线,2019考研山东大学复试分数线已公布
  6. 近年最佳加密软件:免费、付费、商业工具与服务
  7. Redis:我是如何与客户端进行通信的
  8. 怎样关闭百度云开机启动服务器,教你解决win10系统设置百度云管家开机自动启动的设置办法...
  9. 《三国武神赵云传》隐私政策
  10. Android 判断view 是否在屏幕中展示出来(打点真实展现)