使用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中加入:
[mysqld]
wait_timeout=31536000
interactive_timeout=31536000
重启生效,需要同时修改这两个参数。
相关推荐
com.mysql.jdbc.CommunicationsException Communications link failure due to underlying exception:
特好用的FTP管理工具特好用的FTP管理工具特好用的FTP管理工具
java 连接数据库资源包 mysql-connector-java-8.0.23.zip druid-1.2.8.jar
期间调用数据库时总是不成功,如果单独写一个类,并编译执行访问数据库,正常,但是用web应用来调这个类连接数据库,就会出现错误:com.mysql.jdbc.CommunicationsException: Communications link failure due to ...
主要介绍了pycharm工具连接mysql数据库失败问题及解决方法,非常不错大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
包含 SqlServer Mysql Access 。。。。等驱动都有。
主要介绍了阿里云ECS云服务器(linux系统)安装mysql后远程连接不了(踩坑),小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
Of course, to use the new functions one must link the application code with the new .lib file containing these functions. Previous release: 1.20 Release date December 3rd, 2003 Known bugs: a) there ...
Viewing Wireless Communications 197 Signal Tester 197 Spectrum Analyzer 199 Packet Analyzer 199 Network Connectivity Issues 200 Network Interface Problems 200 Faulty Client Cards 201 Wireless Coverage...
applications as executables or dynamic link libraries, including as OCX ActiveX Controls or ActiveX Forms, excepting compilation as design-time packages or compilation into a DLL or OCX for use in a...
applications as executables or dynamic link libraries, including as OCX ActiveX Controls or ActiveX Forms, excepting compilation as design-time packages or compilation into a DLL or OCX for use in a...
Vagaa does not have any responsibility or liability for any information, data, communications, products or materials available on such third-party sites. These linked and framed sites are only for ...