当前位置:网站首页>mysql设置会话超时时间
mysql设置会话超时时间
2022-07-30 06:12:00 【weixin_44953227】
问题
mysql的默认设置下,当一个连接的空闲时间超过8小时后,mysql 就会断开该连接,而连接池认为连接依然有效。在这种情况下,如果客户端代码向连接池请求连接的话,连接池就会把已经失效的连接返回给客户端,客户端在使用该失效连接的时候即抛出异常。类似如下异常:
2022-07-28 19:40:05.618 [http-nio-7072-exec-7] WARN org.hibernate.engine.jdbc.spi.SqlExceptionHelper --info-- SQL Error: 0, SQLState: null 2022-07-28 19:40:05.618 [http-nio-7072-exec-7] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper --info-- connection disabled 2022-07-28 19:40:05.625 [http-nio-7072-exec-7] ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/admin-api].[dispatcherServlet] --info-- Servlet.service() for servlet [dispatcherServlet] in context with path [/admin-api] threw exception [Request processing failed; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not prepare statement] with root cause java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
解决方法
框架用的druid连接池,目前mysql8暂未找到配置自动重连的有效实现方式,在配置文件把mysql会话超时时间改成wait_timeout = 432000和interactive_timeout = 432000来解决,即设置超时时间为5天。
边栏推荐
猜你喜欢

Vue项目通过node连接MySQL数据库并实现增删改查操作

MySQL master-slave replication configuration construction, one step in place

“AI教练”请进家,家庭智能健身蓬勃发展

万能js时间日期格式转换

Electron之初出茅庐——搭建环境并运行第一个程序

预测人们对你的第一印象,“AI颜狗”的诞生

2020 ACM | MoFlow: An Invertible Flow Model for Generating Molecular Graphs

From catching up to surpassing, domestic software shows its talents

2020 数学建模之旅

Go语学习笔记 - gorm使用 - 数据库配置、表新增 Web框架Gin(七)
随机推荐
Keil软件中map文件解析
The usage of window.open(), js opens a new form
go : 使用gorm创建数据库记录
interface
限塑令下的新材料——聚乳酸(PLA)
go : 使用gorm修改数据
The newcomer deleted data by mistake, and the team leader skillfully used MySQL master-slave replication to delay the recovery of losses
New breakthrough in artificial muscle smart materials
How to use Swagger, say goodbye to postman
RAID disk array
this and super
万能js时间日期格式转换
MySQL题外篇【ORM思想解析】
雷总个人博客看到
C语言自定义类型详解
Max Sum Plus Plus HDU - 1024
From catching up to surpassing, domestic software shows its talents
什么是微服务?
ETL为什么经常变成ELT甚至LET?
How does Redis prevent oversold and inventory deduction operations?