当前位置:网站首页>mysql连接超过八小时报错
mysql连接超过八小时报错
2022-08-09 01:37:00 【CSDN问答】
mysql空闲时间超过8小时断开连接
ssm项目配置多数据源,原本使用jndi,自己使用jdbc封装一个工具类,数据驱动使用hutool的DruidFactory
问题相关代码,请勿粘贴截图
public MyDataSource getDateSource() { Setting setting = new Setting("classpath:db.setting"); DataSource dataSource = DruidDSFactory.create(setting).getDataSource(); return new MyDataSource(dataSource); }
db.setting内容
HikariCP配置
自动提交
autoCommit = true
等待连接池分配连接的最大时长(毫秒),超过这个时长还没可用的连接则发生SQLException, 缺省:30秒
connectionTimeout = 30000
一个连接idle状态的最大时长(毫秒),超时则被释放(retired),缺省:10分钟
idleTimeout = 600000
一个连接的生命时长(毫秒),超时而且没被使用则被释放(retired),缺省:30分钟,建议设置比数据库超时时长少30秒,参考MySQL wait_timeout参数(show variables like '%timeout%';)
maxLifetime = 28760000
获取连接前的测试SQL
connectionTestQuery = SELECT 1
最小闲置连接数
minimumIdle = 20
连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count)
maximumPoolSize = 200
连接只读数据库时配置为true, 保证安全
readOnly = false
运行结果及报错内容
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: The last packet successfully received from the server was 51,144,209 milliseconds ago. The last packet sent successfully to the server was 51,144,224 milliseconds ago. 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 property 'autoReconnect=true' to avoid this problem.
我的解答思路和尝试过的方法
更改HikariCP配置没有效果
我想要达到的结果
如何才能超时八个小时后还能继续连接
边栏推荐
猜你喜欢
随机推荐
Grid布局介绍
Go-7-RESTful API的设计
Cmake 报错 Could not find a package configuration file provided by “OpenCV“
torchversion.transforms的使用
Wireshark抓包工具
低代码开发创新企业应用构建模式
typescript89-展示任务列表功能
4-1 Matplotlib库 数据分析常用图
远程控制项目遇到的bug
JDBC technology (2) - set up common sql and configuration files
在实际工作中如何开展性能测试?
typescript91-添加任务基本实现
OpenSceneGraph3.5.1编译
makefile文件编译
如何在群晖系统中安装cpolar(群晖6.X版)
JDBC技术(一)——一个简单的JDBC测试
【图像去噪】基于边缘增强扩散 (cEED) 和 Coherence Enhancing Diffusion (cCED) 滤波器实现图像去噪附matlab代码
字符串压缩
谷歌翻译软件-免费谷歌翻译
Go-12-结构体