wait_timeout过大造成太多sleep

文章详细介绍了在使用Cacti监控系统时遇到的问题,即MySQL产生的大量睡眠连接导致Cacti查询受阻。通过分析MySQL状态和参数设置,作者调整了wait_timeout和interactive_timeout参数,成功解决了MySQL连接泄漏问题,保障了Cacti图形生成的稳定性和效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装了cacti 0.8.7b 运行几天之后,发现生成的图形断断续续。查找原因发现是mysql产生了很多sleep连接不释放,以致影响cacti的查询。
mysql> show processlist;
发现sleep很多+—-+———–+———–+——-+———+——+——-+——————+
| Id | User      | Host      | db    | Command | Time | State | Info             |
+—-+———–+———–+——-+———+——+——-+——————+
|  1 | root      | localhost | NULL  | Query   |    0 | NULL  | show processlist |
|  3 | cactiuser | localhost | cacti | Sleep   |  409 |       | NULL             |
|  4 | cactiuser | localhost | cacti | Sleep   |  403 |       | NULL             |
|  5 | cactiuser | localhost | cacti | Sleep   |  406 |       | NULL             |
| 20 | cactiuser | localhost | cacti | Sleep   |  401 |       | NULL             |
| 22 | cactiuser | localhost | cacti | Sleep   |  199 |       | NULL             |
| 23 | cactiuser | localhost | cacti | Sleep   |  179 |       | NULL             |
| 24 | cactiuser | localhost | cacti | Sleep   |  158 |       | NULL             |
| 25 | cactiuser | localhost | cacti | Sleep   |  134 |       | NULL             |
| 26 | cactiuser | localhost | cacti | Sleep   |  114 |       | NULL             |
| 41 | cactiuser | localhost | cacti | Sleep   |   90 |       | NULL             |
| 42 | cactiuser | localhost | cacti | Sleep   |   69 |       | NULL             |
| 43 | cactiuser | localhost | cacti | Sleep   |   48 |       | NULL             |
| 44 | cactiuser | localhost | cacti | Sleep   |   28 |       | NULL             |
| 45 | cactiuser | localhost | cacti | Sleep   |    4 |       | NULL             |
+—-+———–+———–+——-+———+——+——-+——————+
15 rows in set (0.00 sec)
 
mysql> show variables like ‘max_connections’;
+—————–+——-+
| Variable_name   | Value |
+—————–+——-+
| max_connections | 100   |
+—————–+——-+
1 row in set (0.00 sec)
 
mysql> show status like ‘max_used_connections’;
+———————-+——-+
| Variable_name        | Value |
+———————-+——-+
| Max_used_connections | 24    |
+———————-+——-+
1 row in set (0.00 sec)
 
mysql> show status like ‘thread%’;
+——————-+——-+
| Variable_name     | Value |
+——————-+——-+
| Threads_cached    | 0     |
| Threads_connected | 19    |
| Threads_created   | 29    |
| Threads_running   | 1     |
+——————-+——-+
4 rows in set (0.00 sec)
 
mysql> show variables like ‘wait_timeout’;
+—————+——-+
| Variable_name | Value |
+—————+——-+
| wait_timeout  | 28800 |
+—————+——-+
1 row in set (0.00 sec)
 
修改my.cnf
在[mysqld]增加如下2行:
wait_timeout = 30
interactive_timeout = 30
 
重启数据库
 
mysql> show variables like ‘wait_timeout’;
+—————+——-+
| Variable_name | Value |
+—————+——-+
| wait_timeout  | 30 |
+—————+——-+
1 row in set (0.00 sec)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值