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

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 的值(根据业务情况来判断)。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值