帮助中心 >  技术知识库 >  数据库 >  数据库管理 >  MySQL数据库经典错误 十一 MySQL 数据库连接超时的报错

MySQL数据库经典错误 十一 MySQL 数据库连接超时的报错

2018-11-08 20:26:00 15867

MySQL 数据库连接超时的报错

org.hibernate.util.JDBCExceptionReporter – SQL Error:0, SQLState: 08S01 
org.hibernate.util.JDBCExceptionReporter – The last packet successfully received from the server was43200 milliseconds ago.The last packet sent successfully to the server was 43200 milliseconds 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 ‘autoReconnect=true’ to avoid this problem. 
org.hibernate.event.def.AbstractFlushingEventListener – Could not synchronize database state with session 
org.hibernate.exception.JDBCConnectionException: Could not execute JDBC batch update 
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Connection.close() has already been called. Invalid operation in this state. 
org.hibernate.util.JDBCExceptionReporter – SQL Error:0, SQLState: 08003 
org.hibernate.util.JDBCExceptionReporter – No operations allowed after connection closed. Connection was implicitly closed due to underlying exception/error: 
** BEGIN NESTED EXCEPTION **

大多数做 DBA 的同学,可能都会被开发人员告知,你们的数据库报了这个错误了,赶紧看看是哪里的问题。

这个问题是由两个参数影响的,wait_timeout 和 interactive_timeout。

数据默认的配置时间是 28800(8小时)意味着,超过这个时间之后,MySQL 数据库为了节省资源,就会在数据库端断开这个连接,MySQL 服务器端将其断开了,但是我们的程序再次使用这个连接时没有做任何判断,所以就挂了。

解决思路:先要了解这两个参数的特性,这两个参数必须同时设置,而且必须要保证值一致才可以。

我们可以适当加大这个值,8 小时太长了,不适用于生产环境。因为一个连接长时间不工作,还占用我们的连接数,会消耗我们的系统资源。

解决方法:可以适当在程序中做判断,强烈建议在操作结束时更改应用程序逻辑以正确关闭连接,然后设置一个比较合理的 timeout 的值(根据业务情况来判断)。


提交成功!非常感谢您的反馈,我们会继续努力做到更好!

这条文档是否有帮助解决问题?

非常抱歉未能帮助到您。为了给您提供更好的服务,我们很需要您进一步的反馈信息:

在文档使用中是否遇到以下问题: