当前位置:网站首页>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天。
边栏推荐
- IDEA搜索插件无结果一直转圈圈的解决办法
- “AI教练”请进家,家庭智能健身蓬勃发展
- 02 多线程与高并发 - synchronized 解析
- ARM体系结构概述
- No, the Log4j vulnerability hasn't been fully fixed yet?
- go : go-redis list operation
- export , export default,import完整用法
- Basic usage of tree arrays
- 2020 ACM | MoFlow: An Invertible Flow Model for Generating Molecular Graphs
- golang : Zap日志整合
猜你喜欢

UDP和TCP使用同一个端口,可行吗?

Interview with Ant: How do these technology pioneers do the bottom-level development well?| Excellent technical team interview

2020 数学建模之旅

云服务器零基础部署网站(保姆级教程)

IDEA 中CheckStyle安装及使用

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

C language custom types, rounding

【MySQL】MySQL中如何实现分页操作

Universal js time date format conversion

How does Redis prevent oversold and inventory deduction operations?
随机推荐
包含min函数的栈(js)
架构设计指南 如何成为架构师
go : use gorm to modify data
No, the Log4j vulnerability hasn't been fully fixed yet?
Go uses freecache for caching
LSF提交作业命令--bsub
Handler消息机制-Native层
SkiaSharp 之 WPF 自绘 拖曳小球(案例版)
Electron使用romote报错 : Uncaught TypeError: Cannot read property ‘BrowserWindow‘ of undefined
2020 数学建模之旅
sizeof
物联网网关该怎么选
DP5340国产替代CM5340立体声音频A/D转换器芯片
MYSQL下载及安装完整教程
DNS domain name resolution services
go : go-redis list operation
go : 使用 grom 删除数据库数据
Electron之初出茅庐——搭建环境并运行第一个程序
How does Redis prevent oversold and inventory deduction operations?
interface