【JAVA开发报错分析】Spring Boot com.alibaba.druid.pool.DruidDataSource 数据库连接失效

网友投稿 345 2022-12-02

【JAVA开发报错分析】Spring Boot com.alibaba.druid.pool.DruidDataSource 数据库连接失效

一、问题描述

本来正常运行的Spring Boot项目突然报错

2020-05-10 11:57:10.054 [ERROR com.alibaba.druid.pool.DruidPooledStatement - CommunicationsException, druid version 1.1.12, jdbcUrl : jdbc:mysql://dev001:3306/video_chat?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false&serverTimezone=Asia/Shanghai, testWhileIdle true, idle millis 36820, minIdle 0, poolingCount 0, timeBetweenEvictionRunsMillis 60000, lastValidIdleMillis 36820, driver com.mysql.cj.jdbc.Driver, exceptionSorter com.alibaba.druid.pool.vendor.MySqlExceptionSorter2020-05-10 11:57:10.054 [ERROR com.alibaba.druid.pool.DruidDataSource - discard connectionCaused by: com.mysql.cj.exceptions.CJCommunicationsException: The last packet successfully received from the server was 36,820 milliseconds ago. The last packet sent successfully to the server was 36,820 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 jdk.internal.reflect.GeneratedConstructorAccessor135.newInstance(Unknown Source) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481) at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167) at com.mysql.cj.protocol.a.NativeProtocol.readMessage(NativeProtocol.java:555) at com.mysql.cj.protocol.a.NativeProtocol.checkErrorMessage(NativeProtocol.java:725) at com.mysql.cj.protocol.a.NativeProtocol.sendCommand(NativeProtocol.java:664) at com.mysql.cj.protocol.a.NativeProtocol.sendQueryPacket(NativeProtocol.java:979) at com.mysql.cj.NativeSession.execSQL(NativeSession.java:1153) at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:951) ... 109 common frames omittedCaused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost. at com.mysql.cj.protocol.FullReadInputStream.readFully(FullReadInputStream.java:67) at com.mysql.cj.protocol.a.SimplePacketReader.readHeader(SimplePacketReader.java:63) at com.mysql.cj.protocol.a.SimplePacketReader.readHeader(SimplePacketReader.java:45) at com.mysql.cj.protocol.a.TimeTrackingPacketReader.readHeader(TimeTrackingPacketReader.java:52) at com.mysql.cj.protocol.a.TimeTrackingPacketReader.readHeader(TimeTrackingPacketReader.java:41) at com.mysql.cj.protocol.a.MultiPacketReader.readHeader(MultiPacketReader.java:54) at com.mysql.cj.protocol.a.MultiPacketReader.readHeader(MultiPacketReader.java:44) at com.mysql.cj.protocol.a.NativeProtocol.readMessage(NativeProtocol.java:549) ... 114 common frames omitted

二、问题分析

1. mysql连接失败,看样子可以通过配置参数autoReconnect=true解决

三、问题原因

1. 在使用mysql是的时候,如果超过默认8小时数据库没有操作,会自动断开连接,于是我查看测试服务器的连接超时时间居然是30s

mysql> show global variables like 'wait_timeout';+---------------+-------+| Variable_name | Value |+---------------+-------+| wait_timeout | 30 |+---------------+-------+1 row in set (0.00 sec)

四、问题解决方案

1. set global variables wait_timeout=86400

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Java的方法和this关键字如何理解与应用
下一篇:Python 编码规范(Google) (一)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~