# springboot 项目mysql 连接过多问题排查与解决

## 解决

###### 1、

SELECT count(*) FROM information_schema.PROCESSLIST WHERE DB = ‘bcloud_dev001’

SELECT * FROM information_schema.PROCESSLIST WHERE DB = ‘bcloud_test001’ ORDER BY TIME desc limit 50

###### 2、

🔢minimumIdle
This property controls the minimum number of idle connections that HikariCP tries to maintain in the pool. If the idle connections dip below this value and total connections in the pool are less than maximumPoolSize, HikariCP will make a best effort to add additional connections quickly and efficiently. However, for maximum performance and responsiveness to spike demands, we recommend not setting this value and instead allowing HikariCP to act as a fixed size connection pool. Default: same as maximumPoolSize

#指定连接池初始化连接数
spring.datasource.minimum-idle=20
#指定连接池最大的连接数，包括使用中的和空闲的连接
spring.datasource.maximum-pool-size=500


## 多说下 wait-timeout

mysql的wait-timeout 这个配置针对jdbc连接mysql的情况。如果在mysql中有大量的sleep的连接，那么设置这个参数就显得很有必要。它的作用是在设定的时间内关闭sleep的连接。默认值28800（8个小时）

show global variables like ‘wait_timeout’;

set GLOBAL wait_timeout=30