mysql连接超时的属性设置
mysql连接超时的属性设置
2022-10-26 11:09:54.128 [http-nio-6788-exec-5] ERROR o.s.t.i.TransactionAspectSupport#completeTransactionAfterThrowing [line:525] - Application exception overridden by rollback exceptionorg.springframework.dao.RecoverableDataAccessException:
### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 497,470,876 milliseconds ago.
The last packet sent successfully to the server was 497,470,876 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.
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 497,470,876 milliseconds ago. The last packet sent successfully to the server was 497,470,876 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.
Caused by: java.net.SocketException: Broken pipe (Write failed)
大概意思是当前的connection所进行过的最新请求是在52,587秒之前,这个时间是大于服务所配置的wait_timeout时间的。
原因分析:
MySQL连接时,服务器默认的“wait_timeout”是8小时,也就是说一个connection空闲超过8个小时,Mysql将自动断开该connection。connections如果空闲超过8小时,Mysql将其断开,而DBCP连接池并不知道该connection已经失效,如果这时有Client请求connection,DBCP将该失效的Connection提供给Client,将会造成异常。
打开MySQL的控制台,运行:SHOW VARIABLES LIKE '%timeout%'; 查看和连接时间有关的MySQL系统变量。
- ##修改调整配置:True 修改为 true,min-idle 修改为 0
- spring.datasource.max-idle = 30
- spring.datasource.min = 0
- spring.datasource.min-idle = 0
- spring.datasource.remove-abandoned = true
- spring.datasource.remove-abandoned-timeout = 180
- spring.datasource.test-on-borrow = true
- spring.datasource.test-while-idle = true
- spring.datasource.tomcat.max-idle = 30
- spring.datasource.tomcat.min = 0
- spring.datasource.tomcat.min-idle = 0
- spring.datasource.tomcat.remove-abandoned = true
- spring.datasource.tomcat.remove-abandoned-timeout = 180
- spring.datasource.tomcat.test-on-borrow = true
- spring.datasource.tomcat.test-while-idle = true
配置属性后,从上一次启动服务到测试,间隔几天后,接口操作数据库可以正常访问。
mysql连接超时的属性设置的更多相关文章
- MySQL连接问题【如何解决MySQL连接超时关闭】
--MySQL连接问题[如何解决MySQL连接超时关闭] ------------------------------------------------转载 最近做网站有一个站要用到WEB网页采集器 ...
- mysql连接超时的问题
使用Hibernate + MySQL数据库开发,链接超时问题: com.mysql.jdbc.CommunicationsException: The last packet successfull ...
- mysql 连接超时解决方案: 怎样修改默认超时时间
mysql数据库有一个wait_timeout的配置,默认值为28800(即8小时). 在默认配置不改变的情况下,如果连续8小时内都没有访问数据库的操作,再次访问mysql数据库的时候,mysql数据 ...
- 转 MySQL连接超时
在负载较重的MySQL服务器上,有时你偶尔会看到一些连接超时的错误,诸如: Can’t connect to MySQL server on ‘mydb’(110).如果当时你有多个连接请求,你会发现 ...
- 如何解决MySQL连接超时关闭
最近做网站有一个站要用到WEB网页采集器功能,当一个PHP脚本在请求URL的时候,可能这个被请求的网页非常慢慢,超过了mysql的 wait-timeout时间,然后当网页内容被抓回来后,准备插入到M ...
- mysql连接超时问题
前几天使用个脚本不停的查看redis队列中的事件.如果有则把事件取出来,然后进行一些数据库操作. 后来发现,每天的第一次有事件时都会到导致,找不到数据. 后来定位到问题,是mysql在连接长时间无活动 ...
- mysql 连接超时的问题
项目中用mycat做的分表分库,异步通知系统会连接mycat去查数据库数据,有时会抛异常提示mysql server has gone away.最初以为是mycat的问题,在修改了mycat的配置, ...
- mysql连接超时的问题处理
1. 内网 ts 连接mysql 有时候会连接失败, 原因是 连接超时, 当时所有服务器一起启动,抢占资源,导致连接超过10s. 现在增加一次连接机会, 增加一些日志. 2. 并且对mysql 全局参 ...
- 【转】MySQL连接超时断开的问题
这遍文章转过来做个笔记,时不时看看. 转:http://blog.csdn.net/nethibernate/article/details/6658855 Exception如下: org.hi ...
- mysql连接超时
这几天在跟踪一个项目的时候,老是发现mysql连接报timeout的异常. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException ...
随机推荐
- 阿里云服务网格ASM集成SLS告警
简介:随着微服务的流行,微服务的架构也在不断的发展演进,Spring Cloud 与 Dubbo为代表的微服务开发框架也得到了普及和落地:在云原生时代,无侵入的服务网格(Service Mesh)开 ...
- DataWorks功能实践速览 — 参数透传
简介: DataWorks功能实践系列,帮助您解析业务实现过程中的痛点,提高业务功能使用效率! 往期回顾: DataWorks 功能实践速览01期--数据同步解决方案:为您介绍不同场景下可选的数 ...
- 浏览器扩展开发-Firefox临时载入附加组件(图)
科普:[FE] Quasar BEX 热加载区别: Chrome vs Firefox 1. 2. 3. Thats all. Refer:Firefox扩展开发 Link:https://www. ...
- 读书笔记 dotnet 的字符串在内存是如何存放
本文是读伟民哥翻译的 .NET内存管理宝典 这本书的笔记,我认为读书的过程也需要实践,这样对一知半解的知识也有较为清晰的了解.在阅读到 string 在内存的布局时,我看到 RuntimeHelper ...
- ESP32 使用LVGL案例
一.完成LVGL移植 在使用LVGL提供的测试案例时,需要先移植LVGL,不明白的小伙伴看我之前的笔记 esp-idf 移植 lvgl8.3.3. 移植完成后的项目文件如下图所示 二.添加需要的测试案 ...
- 一文搞懂Maven配置,从此不再糊涂下载依赖(文末有成品)
一般来说Maven都是配合着idea一起使用,下载依赖速度慢就去网上找个镜像配置一下,但总会遇到莫名其妙的问题,比如镜像源不生效.Error reading file pom.xml等等.今天详细讲解 ...
- Windows下绑定线程到指定的CPU核心
在某些场景下,需要把程序绑定到指定CPU核心提高执行效率.通过微软官方文档查询到Windows提供了两个Win32函数:SetThreadAffinityMask和SetProcessAffinity ...
- Django配置loguru来记录日志
第一步: 在settings.py文件中导入loguru模块并配置日志文件路径和格式等信息 from loguru import logger BASE_DIR = Path(__file__).re ...
- 利用PostMan 模拟上传/下载文件
我们经常用postman模拟各种http请求.但是有时候因为业务需要,我们需要测试上传下载功能.其实postman也是很好支持这两种操作的. 一.上传文件: 1.打开postman 选择对应reque ...
- 安装assimp失败
使用Cmake和Visual Studio编译assimp成功(包括Debug和Release),并且安装Release版本也成功,但安装debug版本失败,安装输出信息如下: 通过提示找到脚本文件, ...