Communications link failure ,The last packet successfully received from the server was 18,903 millis

今天开发环境出现连接数据报以下错误,错误信息如下:


The last packet successfully received from the server was 18,903 milliseconds ago.  
The last packet sent successfully to the server was 18,901 milliseconds ago.; 
nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure


The last packet successfully received from the server was 18,903 milliseconds ago.  The last packet sent successfully to the server was 18,901 milliseconds ago.
  at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:98) ~[spring-jdbc-4.2.7.RELEASE.jar:4.2.7.RELEASE]
  at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) ~[spring-jdbc-4.2.7.RELEASE.jar:4.2.7.RELEASE]
  at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-4.2.7.RELEASE.jar:4.2.7.RELEASE]
  at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75) ~[mybatis-spring-1.3.0.jar:1.3.0]
  at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:447) ~[mybatis-spring-1.3.0.jar:1.3.0]
  at com.sun.proxy.$Proxy97.selectList(Unknown Source) ~[na:na]
  at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:231) ~[mybatis-spring-1.3.0.jar:1.3.0]
  at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:128) ~[mybatis-3.4.0.jar:3.4.0]
  at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:68) ~[mybatis-3.4.0.jar:3.4.0]
  at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53) ~[mybatis-3.4.0.jar:3.4.0]
  at com.sun.proxy.$Proxy117.listOfCirculationOrderBy(Unknown Source) ~[na:na]
  at com.cloud.saas.official.service.impl.CirculationServiceImpl.listOfCirculationOrderBy(CirculationServiceImpl.java:98) ~[classes/:na]
  at com.cloud.saas.official.service.impl.CirculationServiceImpl$$FastClassBySpringCGLIB$$7c31abe8.invoke() ~[classes/:na]
  at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.2.7.RELEASE.jar:4.2.7.RELEASE]
  at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720) ~[spring-aop-4.2.7.RELEASE.jar:4.2.7.RELEASE]
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.2.7.RELEASE.jar:4.2.7.RELEASE]
  at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.2.7.RELEASE.jar:4.2.7.RELEASE]
  at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) ~[spring-tx-4.2.7.RELEASE.jar:4.2.7.RELEASE]
  at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.2.7.RELEASE.jar:4.2.7.RELEASE]
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.7.RELEASE.jar:4.2.7.RELEASE]
  at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655) ~[spring-aop-4.2.7.RELEASE.jar:4.2.7.RELEASE]
  at com.cloud.saas.official.service.impl.CirculationServiceImpl$$EnhancerBySpringCGLIB$$a6c1c39a.listOfCirculationOrderBy() ~[classes/:na]
  at com.cloud.saas.official.controller.CirculationController.listOfCirculation(CirculationController.java:79) ~[classes/:na]

出现问题还是百度、Google查询,这错误还是比较常见的,出现这错误的原因:

        MySQL服务器默认的“wait_timeout”是28800秒即8小时,意味着如果一个连接的空闲时间超过8个小时,MySQL将自动断开该连接,而连接池却认为该连接还是有效的(因为并未校验连接的有效性),当应用申请使用该连接时,就会导致上面的报错。
修改MySQL的参数了,wait_timeout最大为31536000即1年,在my.cnf中加入:

[mysqld]
wait_timeout=31536000
interactive_timeout=31536000

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

我这里是用Docker 起的mysql5.7的,所以可以直接用以下命令加入以上参数:

docker exec mysql bash -c "echo 'wait_timeout=31536000' >> /etc/mysql/mysql.conf.d/mysqld.cnf"
docker exec mysql bash -c "echo 'interactive_timeout=31536000' >> /etc/mysql/mysql.conf.d/mysqld.cnf"

docker restart mysql



你可能感兴趣的:(Mysql,Docker)