日志:using the Connector/J connection property 'autoReconnect=true' to avoid this problem
来源:互联网 发布:手机下载在线视频软件 编辑:程序博客网 时间:2024/06/13 17:20
碰上:
ERROR o.h.e.jdbc.spi.SqlExceptionHelper - The last packet successfully received from the server was 236,095,086 milliseconds ago. The last packet sent successfully to the server was 236,095,086 milliseconds ago. 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.
2017-11-13 09:13:20.434 ERROR 20138 --- [nio-8081-exec-5] o.s.t.i.TransactionInterceptor : Application exception overridden by rollback exception
javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: could not extract ResultSet
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
at org.hibernate.jpa.internal.QueryImpl.getSingleResult(QueryImpl.java:524) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
at org.hibernate.jpa.criteria.compile.CriteriaQueryTypeQueryAdapter.getSingleResult(CriteriaQueryTypeQueryAdapter.java:71) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
at org.springframework.data.jpa.repository.query.JpaQueryExecution$SingleEntityExecution.doExecute(JpaQueryExecution.java:206) ~[spring-data-jpa-1.9.2.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:78) ~[spring-data-jpa-1.9.2.RELEASE.jar:na]
at org.springframework.data.jpa.repository.quer
于是参考:
https://www.cnblogs.com/fanelephant/p/4216083.html
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
重启生效,需要同时修改这两个参数。
http://blog.csdn.net/u011537073/article/details/73522576
在Spring Boot JPA连接Mysql的过程中,经过 8小时后会发现断连的情况。application.properties配置如下(此坑我跳过,欢迎入坑):
原因分析:
mysql在默认的情况下,如果发现一个连接空闲时间超过8小时,将会在数据库端自动关闭这个连接。(mysql wait_timeout 为8小时)。
解决方式:
1 . Mysql 5 版本之前可以通过在URL后面加入autoReconnect=true,如:
2 . application.properties文件中加入:
3 . 粗暴点的直接修改 wait_timeout 时间:
推荐第二种方式
2验证可用
- 日志:using the Connector/J connection property 'autoReconnect=true' to avoid this problem
- using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
- using the Connector/J connection property 'autoReconnect=true' to avoid this problem
- using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
- mysql超时设置的问题 using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
- Connector/J connection property 'autoReconnect=true' to avoid this problem
- 连接数据库地址后面加上?autoReconnect=true&useUnicode=true&characterEncoding=utf8 日志
- 连接数据库超时设置autoReconnect=true
- 连接数据库超时设置autoReconnect=true
- 连接数据库超时设置autoReconnect=true
- 连接数据库超时设置autoReconnect=true
- Using Handler to Avoid ANR
- Avoid Using The “system("pause")” !
- java.sql.SQLException: The connection property 'useUnicode' only accepts values of the form: 'true',
- Problem J. Journey to the “The World’s Start”
- The HttpsGetEnabled property of ServiceMetdataBehavior is set to true and the HttpsGetUrl property
- 异常:calling prepareStatement is no longer allowed! Increase reapTimeout to avoid this problem
- Hibernate连接数据库超时设置autoReconnect=true(Mysql)
- TimeQuest之delay_fall clock_fall傻傻分不清楚
- vagrant init命令及其他一些命令
- 6.4
- 第一次做小游戏
- POJ-1159 Palindrome (区间dp)
- 日志:using the Connector/J connection property 'autoReconnect=true' to avoid this problem
- java日常学习:System系统类
- HTML&CSS实验(3)
- 总结二
- mysql 5.7.15 union order by 子查询排序不生效
- Educational Codeforces Round 32 G. Xor-MST 01字典树+二叉树 (板子
- zabbix监控elasticSearch集群健康值green yellow red状态
- javascript 函数作用域中的关键字this
- 巩固与修炼(五)