日志:using the Connector/J connection property 'autoReconnect=true' to avoid this problem

com.mysql.jdbc.CommunicationsException: The last packet successfully received from the server was58129 seconds ago.The last packet sent successfully to the server was 58129 seconds ago, which is longer than the server configured value of ‘wait_timeout‘. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property ‘autoReconnect=true‘ to avoid this problem.

查了一下,原来是mysql超时设置的问题
如果连接闲置8小时 (8小时内没有进行数据库操作), mysql就会自动断开连接, 要重启tomcat.

解决办法:

第一种:如果不用hibernate的话, 则在 connection url中加参数: autoReconnect=true

1 jdbc.url=jdbc:mysql://ipaddress:3306/database?autoReconnect=true&autoReconnectForPools=true

第二种:用hibernate的话, 加如下属性:

1 <property name="connection.autoReconnect">true</property>
2 <property name="connection.autoReconnectForPools">true</property>
3 <property name="connection.is-connection-validation-required">true</property>

第三种:要是还用c3p0连接池:

1 <property name="hibernate.c3p0.acquire_increment">1</property>
2 <property name="hibernate.c3p0.idle_test_period">0</property>
3 <property name="hibernate.c3p0.timeout">0</property>
4 <property name="hibernate.c3p0.validate">true</property>

第四种:最不好的解决方案

使用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将自动断开该 连接,而连接池却认为该连接还是有效的(因为并未校验连接的有效性),当应用申请使用该连接时,就会导致上面的报错。

⑴.按照错误的提示,可以在JDBC URL中使用autoReconnect属性,实际测试时使用了autoReconnect=true& failOverReadOnly=false,不过并未起作用,使用的是5.1版本,可能真像网上所说的只对4之前的版本有效。

⑵.没办法,只能修改MySQL的参数了,wait_timeout最大为31536000即1年,在my.cnf中加入:

[mysqld]

wait_timeout=31536000

interactive_timeout=31536000

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

日志:using the Connector/J connection property 'autoReconnect=true' to avoid this problem

时间: 2024-10-23 06:59:46

日志:using the Connector/J connection property 'autoReconnect=true' to avoid this problem的相关文章

连接数据库超时设置autoReconnect=true

mysql经典的8小时问题 链自: http://blog.csdn.net/bluesnail216/article/details/15810119 参考http://www.wang1314.com/doc/topic-1520183-1.html http://www.jb51.net/article/32284.htm 1,问题现象: com.MySQL.jdbc.CommunicationsException: The last packet successfully receive

MySQL Connector/J 6.x jdbc.properties 配置, mysql-connector-java-6.0.4.jar 异常

报错信息 Caused by: com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: The server time zone value '?й???????' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezon

MySQL Connector/J is the official JDBC driver for MySQL

mysql-connector-java-5.0.8.zip          mysql的jdbc驱动(MySQL Connector/J is the official JDBC driver for MySQL.)     http://dev.mysql.com/downloads/file.php?id=13598 zip压缩文件放在百度云:http://pan.baidu.com/disk/home#from=share_pan_logo 解压后得到mysql-connector-j

jdbc autoReconnect=true 参数设置导致 slow log 爆表。

1.过程 同事按照文档上配置了下面的jdbc url: jdbc:mysql://ip:port/db?autoReconnect=true&useUnicode=true&characterEncoding=utf-8 结果导致了 mysql slow log 出现了满屏的 ping 命令, # [email protected]: db[db] @ [ip] # Query_time: 0.000017 Lock_time: 0.000000 Rows_sent: 0 Rows_exa

mysql5 数据库连接丢失问题,autoReconnect=true不起作用

The last packet successfully received from the server was 55,404,563 millise 方案1 定时器 方案2 修改连接池容量 //todo... 原文地址:https://www.cnblogs.com/tenghoo/p/autoreconnect_true.html

Hibernate+C3P0下连接超时总结

最近后台总是会遇到当几个游戏区并发通知后台写入统计数据时,发生连接已超时的问题,抛出如下异常,导致一些统计数据未有写进去. Mysql服务器默认的"wait_timeout"是8小时[也就是默认的值默认是28800秒],也就是说一个connection空闲超过8个小时,Mysql将自动断开该connection,通俗的讲就是一个连接在8小时内没有活动,就会自动断开该连接. wait timeout的值可以设定,但最多只能是2147483,不能再大了.也就是约24.85天 这个参数大致的

线上环境数据库连接超时原因

查看线上日志发现了如下的异常: ERROR 500.jsp - Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 31,680,464 milliseconds ago.  The last packet sent successfully to the

mysql The last packet successfully received from t

本人博客开始迁移,博客整个架构自己搭建及编码 http://www.cookqq.com/lookBlog.action?id=c7d6978a-0dc0-4648-9020-2b81d859a243 mysql服务器最近老是报错,内容如下: The last packet successfully received from the server was 65,502,275 milliseconds ago.  The last packet sent successfully to the

mysql重连,连接丢失问题:The last packet sent successfully to the server was……

1.log错误日志: -org.hibernate.exception.JDBCConnectionException: The last packet successfully received from the server was 51,999,860 milliseconds ago. The last packet sent successfully to the server was 51,999,860 milliseconds ago. is longer than the se