`

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException

 
阅读更多

概述:mysql版本5.6,错误信息如下:

 

### Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 690,750,831 milliseconds ago.  The last packet sent successfully to the server was 690,750,833 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.

; SQL []; The last packet successfully received from the server was 690,750,831 milliseconds ago.  The last packet sent successfully to the server was 690,750,833 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.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 690,750,831 milliseconds ago.  The last packet sent successfully to the server was 690,750,833 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.

at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:98)

at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)

at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)

at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)

at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)

at com.sun.proxy.$Proxy30.insert(Unknown Source)

at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:240)

at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:51)

at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)

at com.sun.proxy.$Proxy42.add(Unknown Source)

at com.atme8.order.serviceImpl.OrderProviderService.add(OrderProviderService.java:83)

at sun.reflect.GeneratedMethodAccessor131.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)

at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)

at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)

at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)

at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)

at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)

at com.sun.proxy.$Proxy47.add(Unknown Source)

at com.alibaba.dubbo.common.bytecode.Wrapper3.invokeMethod(Wrapper3.java)

at com.alibaba.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:46)

at com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:72)

at com.alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:53)

at com.alibaba.dubbo.rpc.filter.ExceptionFilter.invoke(ExceptionFilter.java:64)

at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)

at com.alibaba.dubbo.rpc.filter.TimeoutFilter.invoke(TimeoutFilter.java:42)

at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)

at com.alibaba.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:65)

at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)

at com.alibaba.dubbo.rpc.protocol.dubbo.filter.TraceFilter.invoke(TraceFilter.java:78)

at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)

at com.alibaba.dubbo.rpc.filter.ContextFilter.invoke(ContextFilter.java:70)

at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)

at com.alibaba.dubbo.rpc.filter.GenericFilter.invoke(GenericFilter.java:132)

at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)

at com.alibaba.dubbo.rpc.filter.ClassLoaderFilter.invoke(ClassLoaderFilter.java:38)

at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)

at com.alibaba.dubbo.rpc.filter.EchoFilter.invoke(EchoFilter.java:38)

at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)

at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol$1.reply(DubboProtocol.java:113)

at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest(HeaderExchangeHandler.java:84)

at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:170)

at com.alibaba.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:52)

at com.alibaba.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:82)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

at java.lang.Thread.run(Thread.java:745)

Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 690,750,831 milliseconds ago.  The last packet sent successfully to the server was 690,750,833 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.

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:526)

at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)

at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)

at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3291)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1938)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2107)

at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2648)

at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2086)

at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1365)

at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:44)

at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:69)

at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:48)

at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:105)

at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:71)

at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:152)

at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:141)

at sun.reflect.GeneratedMethodAccessor88.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)

... 46 common frames omitted

Caused by: java.net.SocketException: Broken pipe

at java.net.SocketOutputStream.socketWrite0(Native Method)

at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)

at java.net.SocketOutputStream.write(SocketOutputStream.java:159)

at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)

at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)

at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3272)

... 62 common frames omitted

 

 

根据日志信息,说明链接时间比wait_timeout参数设置的时间要长,那么需要知道现在数据库设置的改参数是多长时间:

mysql﹥ SHOW GLOBAL VARIABLES LIKE 'wait_timeout';

| Variable_name | Value |

+---------------+---------+

| wait_timeout | 28800 |  

该值是28800秒,即8小时。

MySQL服务器默认的“wait_timeout”是28800秒即8小时,意味着如果一个连接的空闲时间超过8个小时,MySQL将自动断开该连接,而连接池却认为该连接还是有效的(因为并未校验连接的有效性),当应用申请使用该连接时,就会导致上面的报错。

 

解决方法:

1、修改/etc/my.cnf: 

[mysqld]  

wait_timeout=31536000  

interactive_timeout=31536000  

将过期时间修改为1年。 

 

2、在连接URL上添加参数:&autoReconnect=true&failOverReadOnly=false 

我使用的是第一种方式,如果不会改修改本篇日志说明相应的配置已经起作用。

以下是我改完的数据库配置:

spring.datasource.url=jdbc:mysql://127.0..1:3306/sevenspay_dev?characterEncoding=utf-8&useUnicode=true&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=convertToNull
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.max-idle=10
spring.datasource.max-wait=60000
spring.datasource.min-idle=5
spring.datasource.max-active=20
spring.datasource.initial-size=5
spring.datasource.validation-query=SELECT 1
spring.datasource.test-on-borrow=false
spring.datasource.test-on-return=false
spring.datasource.test-while-idle=true
spring.datasource.time-between-eviction-runs-millis=18800
spring.datasource.pool-prepared-statements=true
spring.datasource.max-open-prepared-statements=20

 

3、MySQL5可以考虑用druid连接池或者proxool连接池。

 

附上spring datasource的所有参数说明:

https://segmentfault.com/a/1190000004316491#articleHeader0

 

分享到:
评论

相关推荐

    解决Cause com.mysql.jdbc.exceptions.jdbc4.CommunicationsException

    Cause com.mysql.jdbc.exceptions.jdbc4.CommunicationsException The last packet successfully received from the server was 47,795,922 milliseconds ago. The last packet sent successfully to the server was...

    Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: ….. this is incompatible with sq

    1、写在开头 标题之前我想说一下Linux的mysql真的实在是太坑了。太坑了。总是会出现这样那样的你想不到的问题。崩溃了。首先来罗列一下我遇到过的...Cause:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorExcepti

    mysql 异常com.mysql.jdbc.CommunicationsException

    ### MySQL异常com.mysql.jdbc.CommunicationsException解析及解决方案 #### 异常概述 在Java应用程序中使用MySQL数据库时,可能会遇到`com.mysql.jdbc.CommunicationsException`这一异常。该异常通常意味着与MySQL...

    com.mysql.jdbc.PacketTooBigException: Packet for query is too large (11087 > 102

    `com.mysql.jdbc.PacketTooBigException` 是MySQL JDBC驱动抛出的一个异常,它表示在网络传输过程中,发送到服务器的数据包超过了MySQL服务器允许的最大大小。在描述中提到的错误信息 "Packet for query is too ...

    linux 后台日志 mysql 错误异常的解释(推荐)

    1、Caused by: com.MySQL.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 56,201,339 milliseconds ago. The last packet sent successfully to the...

    c-jdbc 详细配置方案

    C-JDBC,全称Cluster JDBC,是一款用于数据库集群的中间件,它允许应用程序同时访问和操作多个数据库,实现数据的同步交换。以下是对C-JDBC的详细配置方案及其相关知识点的解析: 1. **下载与安装**: - 从官方...

    mysql数据库在springboot项目中启动报错问题.docx

    在给定的信息中,我们注意到一个具体的错误信息:“com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Error:GlobalConfigUtils setMetaData Fail !”。这个错误提示表明在使用 MyBatis Plus 时出现...

    MySQL数据库连接异常汇总(值得收藏)

    在Centos上部署项目发现一个奇怪的问题,数据库连接一直抛异常。于是花了两个小时搜了各种数据库连接异常导致的原因,最终问题得以解决。同时,把解决过程中搜集到的异常信息汇总一下,当大家遇到...com.mysql.jdbc.exc

    bitronix 连接 MySQL 出现MySQLSyntaxErrorException 的解决方法

    Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user ''@'localhost' to database 'hibernate' at sun.reflect.NativeConstructorAccessorImpl.new

    mysql8驱动源码.zip

    7. **错误处理**:`com.mysql.cj.jdbc.exceptions` 包下的异常类封装了与数据库交互时可能出现的各种错误,便于开发者进行异常处理。 8. **连接池支持**:驱动支持常见的连接池框架,如 C3P0、HikariCP、Druid 等,...

    mysqljdbc src

    5. **异常处理**:`com.mysql.jdbc.exceptions`包包含了各种可能的数据库交互异常,如`SQLException`,这些异常在出现问题时被抛出,帮助开发者定位问题。 6. **性能优化**:源代码中包含了一些性能优化策略,例如...

    mysql-connector-java-5.1.12.rar 源代码

    MySQL Connector/J 5.1.12 是 MySQL 官方提供的用于 Java 应用程序...3. com.mysql.jdbc.exceptions 包:包含所有由 MySQL Connector/J 抛出的异常类,如 `com.mysql.jdbc.exceptions.MySQLSyntaxErrorException` 和 `...

    Dbvisualizer安装及连接mysql oracle sqlServer配置

    对于MySQL,驱动类名通常是`com.mysql.jdbc.Driver`;Oracle则是`oracle.jdbc.driver.OracleDriver`;而对于SQL Server,驱动类名是`com.microsoft.sqlserver.jdbc.SQLServerDriver`。确保正确选择并输入这些信息,...

    MyEclipse8.x 汉化

    4. **刷新界面**:重启MyEclipse后,大部分界面应该已经变为中文。如果某些地方仍显示英文,可能是因为汉化不完全或者有遗漏。此时,可以尝试清理MyEclipse的缓存,具体操作是关闭MyEclipse,删除.metadata\.plugins...

    Mail服务器应用

    com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:CommunicationslinkfailureLastpacketsenttotheserverwas4msago. ``` **知识点:** - **CommunicationsException**:这是MySQL JDBC驱动程序抛出的一个...

    java mysql驱动源码

    例如,`com.mysql.jdbc.exceptions`包下包含了一系列异常类,用于处理在数据库操作中可能出现的问题。`com.mysql.jdbc.JDBC4Connection`是JDBC 4版本的连接实现,增加了新的特性支持。 深入理解Java MySQL驱动源码...

    mysql的jar

    5. **异常处理**:当数据库操作遇到问题时,会抛出特定的异常,如`com.mysql.jdbc.exceptions.MySQLSyntaxErrorException`和`com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException`等。...

    mysql_jdbc连接数据库-错误提示.pdf

    Exception in thread "main" com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown database 'hrtrain' ``` **解决方法**: - 确认数据库名称是否正确。 - 检查MySQL服务状态,确保其正在运行。 #### 五...

    最美POETIZE个人博客系统源码

    最美POETIZE个人博客系统源码 这是一个 SpringBoot + Vue2 + Vue3 的产物,支持移动端自适应,配有完备的前台和后台管理功能。 网站分两个模块: 博客系统:具有文章,表白墙,图片墙,收藏夹,乐曲,视频播放,...

Global site tag (gtag.js) - Google Analytics