错误原文:
java.sql.SQLNonTransientConnectionException: (conn:22667) Could not send query: unexpected end of exception, read 0 bytes from 4 at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.get(ExceptionMapper.java:156) at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.getException(ExceptionMapper.java:118) at org.mariadb.jdbc.MariaDbStatement.executeExceptionEpilogue(MariaDbStatement.java:245) at org.mariadb.jdbc.MariaDbStatement.executeInternal(MariaDbStatement.java:343) at org.mariadb.jdbc.MariaDbStatement.executeQuery(MariaDbStatement.java:513) ............. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) Caused by: java.sql.SQLException: Could not send query: unexpected end of exception, read 0 bytes from 4 Query is: select 1 at org.mariadb.jdbc.internal.util.LogQueryTool.exceptionWithQuery(LogQueryTool.java:113) at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executeQuery(AbstractQueryProtocol.java:168) at org.mariadb.jdbc.MariaDbStatement.executeInternal(MariaDbStatement.java:337) ... 160 common frames omitted Caused by: java.io.EOFException: unexpected end of exception, read 0 bytes from 4 at org.mariadb.jdbc.internal.io.input.StandardPacketInputStream.getPacketArray(StandardPacketInputStream.java:246) at org.mariadb.jdbc.internal.io.input.StandardPacketInputStream.getPacket(StandardPacketInputStream.java:214) at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.readPacket(AbstractQueryProtocol.java:1047) at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.getResult(AbstractQueryProtocol.java:1028) at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executeQuery(AbstractQueryProtocol.java:165) ... 161 common frames omitted 2019-06-27 17:00:49.508 [http-nio-8083-exec-10] ERROR druid.sql.Statement - {conn-10034, stmt-20086} execute error. select 1 java.sql.SQLNonTransientConnectionException: (conn:22668) Could not send query: unexpected end of exception, read 0 bytes from 4 at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.get(ExceptionMapper.java:156) at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.getException(ExceptionMapper.java:118) at org.mariadb.jdbc.MariaDbStatement.executeExceptionEpilogue(MariaDbStatement.java:245) at org.mariadb.jdbc.MariaDbStatement.executeInternal(MariaDbStatement.java:343) at org.mariadb.jdbc.MariaDbStatement.executeQuery(MariaDbStatement.java:513) .............. Caused by: java.sql.SQLException: Could not send query: unexpected end of exception, read 0 bytes from 4 Query is: select 1 at org.mariadb.jdbc.internal.util.LogQueryTool.exceptionWithQuery(LogQueryTool.java:113) at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executeQuery(AbstractQueryProtocol.java:168) at org.mariadb.jdbc.MariaDbStatement.executeInternal(MariaDbStatement.java:337) ... 160 common frames omitted Caused by: java.io.EOFException: unexpected end of exception, read 0 bytes from 4 at org.mariadb.jdbc.internal.io.input.StandardPacketInputStream.getPacketArray(StandardPacketInputStream.java:246) at org.mariadb.jdbc.internal.io.input.StandardPacketInputStream.getPacket(StandardPacketInputStream.java:214) at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.readPacket(AbstractQueryProtocol.java:1047) at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.getResult(AbstractQueryProtocol.java:1028) at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executeQuery(AbstractQueryProtocol.java:165) ... 161 common frames omitted
原因分析:从错误内容分析可能是连接数据库连接丢失造成的,而连接为什么丢失自然就想到可能是连接超时,所以就试着修改数据库超时时间,然后就真的解决了(意外)。。。在此记录一下
解决方法:
1: 查看当前数据库超时时间设置:
SHOW GLOBAL VARIABLES LIKE '%timeout%';
2:修改相关超时时间:
SET GLOBAL net_write_timeout=28800;
#写超时时间
SET GLOBAL net_read_timeout=6000;
#读超时时间
SET GLOBAL wait_timeout=28800;
#等待超时时间 主要设置此项
3:设置完需要重启项目异常就消失了。注意是重启项目,不是重启数据库,上面设置如果重启数据库需要重新设置。