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连接超时的属性设置的更多相关文章

  1. MySQL连接问题【如何解决MySQL连接超时关闭】

    --MySQL连接问题[如何解决MySQL连接超时关闭] ------------------------------------------------转载 最近做网站有一个站要用到WEB网页采集器 ...

  2. mysql连接超时的问题

    使用Hibernate + MySQL数据库开发,链接超时问题: com.mysql.jdbc.CommunicationsException: The last packet successfull ...

  3. mysql 连接超时解决方案: 怎样修改默认超时时间

    mysql数据库有一个wait_timeout的配置,默认值为28800(即8小时). 在默认配置不改变的情况下,如果连续8小时内都没有访问数据库的操作,再次访问mysql数据库的时候,mysql数据 ...

  4. 转 MySQL连接超时

    在负载较重的MySQL服务器上,有时你偶尔会看到一些连接超时的错误,诸如: Can’t connect to MySQL server on ‘mydb’(110).如果当时你有多个连接请求,你会发现 ...

  5. 如何解决MySQL连接超时关闭

    最近做网站有一个站要用到WEB网页采集器功能,当一个PHP脚本在请求URL的时候,可能这个被请求的网页非常慢慢,超过了mysql的 wait-timeout时间,然后当网页内容被抓回来后,准备插入到M ...

  6. mysql连接超时问题

    前几天使用个脚本不停的查看redis队列中的事件.如果有则把事件取出来,然后进行一些数据库操作. 后来发现,每天的第一次有事件时都会到导致,找不到数据. 后来定位到问题,是mysql在连接长时间无活动 ...

  7. mysql 连接超时的问题

    项目中用mycat做的分表分库,异步通知系统会连接mycat去查数据库数据,有时会抛异常提示mysql server has gone away.最初以为是mycat的问题,在修改了mycat的配置, ...

  8. mysql连接超时的问题处理

    1. 内网 ts 连接mysql 有时候会连接失败, 原因是 连接超时, 当时所有服务器一起启动,抢占资源,导致连接超过10s. 现在增加一次连接机会, 增加一些日志. 2. 并且对mysql 全局参 ...

  9. 【转】MySQL连接超时断开的问题

      这遍文章转过来做个笔记,时不时看看. 转:http://blog.csdn.net/nethibernate/article/details/6658855 Exception如下: org.hi ...

  10. mysql连接超时

    这几天在跟踪一个项目的时候,老是发现mysql连接报timeout的异常. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException ...

随机推荐

  1. 阿里云服务网格ASM集成SLS告警

    ​简介:随着微服务的流行,微服务的架构也在不断的发展演进,Spring Cloud 与 Dubbo为代表的微服务开发框架也得到了普及和落地:在云原生时代,无侵入的服务网格(Service Mesh)开 ...

  2. [GPT] golang 有那么多系统包 该如何了解和学习

    在学习和了解Golang(Go语言)的系统包时,可以遵循以下步骤来逐步熟悉并掌握它们: 1. 官方文档阅读: 首先从官方文档入手,Go的标准库文档非常详尽且易于理解.你可以访问 Go标准库 来查看各个 ...

  3. 003_Orcad菜单讲解与偏好设置

    003_Orcad菜单讲解与偏好设置 菜单栏用的比较多的是File和Options项. 网格建议用lines,比较方便对齐. Auto Reference和Intertool Commuication ...

  4. 为什么需要学习ITSM/ITIL

    假如你需要管理一个超过20人的IT服务组织,一般会面临以下问题: 人多事杂活重,每个人都很累,工作却还是一团糟糕, 用户方怨声载道,领导也颇有微词,同事间也经常互相甩锅埋坑, 工作只是救火或者混日子, ...

  5. homebrew的安装和使用

    目录 背景 安装xcode 安装homebrew 有关报错解决 卸载脚本 homebrew软件搜索 brew 常用命令 brew redis安装 PhpWebStudy安装 安装php 背景 最近用b ...

  6. docker-compose部署Elasticsearch7.14.1+kabana7.14.1+elasticsearch-head并设置账号密码

    学习资料 https://www.bilibili.com/video/BV1eY411w7Lx/ https://www.bilibili.com/video/BV1SQ4y1m7Ds?p=13 仓 ...

  7. rails byebug

    Gemfile里添加 gem 'byebug' bundle install 在要打断点的地方写 byebug byebug -h #帮助 c 放行,入下走 n 单行调适 q 退出进行 启动异步任务推 ...

  8. SQL中常用的字符串REVERSE函数和SUBSTRING函数详解!

    今天继续整理日常可能经常遇到的一些处理字符串的函数,记得点赞收藏!以备不时之需! REVERSE(expression)函数解析:SQL Server中的此函数用于反转(颠倒)指定的字符串,也就是说把 ...

  9. 🔥httpsok-v1.11.0支持OSS证书自动部署

    httpsok-v1.11.0支持OSS证书自动部署 介绍 httpsok 是一个便捷的 HTTPS 证书自动续签工具,专为 Nginx .OpenResty 服务器设计.已服务众多中小企业,稳定.安 ...

  10. three.js教程7-PBR材质与环境贴图CubeTextureLoader

    1.PBR材质 PBR是基于物理的渲染(physically-based rendering).模拟物体表面的反射算法. Three.js提供了两个PBR材质相关的类MeshStandardMater ...