首页 > 数据库 >mysql连接超时的属性设置

mysql连接超时的属性设置

时间:2022-11-04 18:11:54浏览次数:44  
标签:spring idle server connection datasource mysql 超时 true 属性

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

配置属性后,从上一次启动服务到测试,间隔几天后,接口操作数据库可以正常访问。

标签:spring,idle,server,connection,datasource,mysql,超时,true,属性
From: https://www.cnblogs.com/oktokeep/p/16858680.html

相关文章

  • ContOS操作MySQL的基本操作
    一.安装MySQL安装mysqlyuminstall-ymysql-server设置开机自动启动systemctlenablemysqld.service检查开机自动启动是否设置成功systemctllist-unit-files|gre......
  • mysql锁
    一、全局锁全局锁就是对整个数据库实例加锁。MySQL提供了一个加全局读锁的方法,命令是 #全局锁Flushtableswithreadlock 当需要让整个库处于只读状态的时候,可......
  • MySQL函数-Group_Concat分组并行转列
    group_concat函数解析:1、concat()函数:  功能:将多个字符串连接成一个字符串  语法:concat(str1,str2)  结果:连接参数str1,str2为一个字符串,如果有任何一个参数为n......
  • Windows Server 2016部署MySQL 8.0 MGR
    环境介绍操作系统IP主机名MySQL版本WindowsServer2016192.168.1.91db18.0.31WindowsServer2016192.168.1.92db28.0.31WindowsServer2016192.......
  • MySQL---存储引擎
    存储引擎查看存储引擎设置DBMS默认存储引擎设置表的存储引擎创建表时指定存储引擎修改表时指定存储引擎存储引擎介绍......
  • MYSQL数据备份之mysqldump命令详解
    一、mysqldump简介mysqldump是MySQL自带的逻辑备份工具。它的备份原理是通过协议连接到MySQL数据库,将需要备份的数据查询出来,将查询出的数据转换成对应的insert语......
  • mysql 5 和 8 连接配置
    前言:mysql目前最常用的就是5和8两个版本,但连接配置有一些区别,以下列出两个模板备用mysql5连接配置spring:datasource:driver-class-name:com.mysql.jd......
  • 学习笔记-mysql
    mysqlmy.cnf配置文件port=3309socket=/usr/local/mysql/tmp/mysql.sock[mysqld]#服务器端配置!include/usr/local/mysql/etc/mysqld.......
  • MySQL
    MySQLMySQL基础篇MySQL概述数据库相关概念名称概念简称数据库存储数据的仓库,数据是有组织的进行存储DataBase(DB)数据库管理系统操纵和管理数据库的大......
  • Installing MySQL-8028 on CentOS 8.3
    一、InstallingMySQL-8028onCentOS8.31地址https://www.mysql.comhttps://downloads.mysql.com/archives/community2下载图片 二、下载&解压1wge......