MySQL连接数Max_used_connections过多处理方法

一、问题描述

        今天突然接到个问题,Mysql内存占用90%多,后来发现有问题就查找到Max_used_connections到达顶峰

二、处理方法

1.查询连接情况

root@localhost > show processlist;

…...
1001 rows in set (0.00 sec)
root@localhost > show variables like '%proces%';
Empty set (0.00 sec)

2.检查参数

root@localhost > show global status like 'Max_used_connections';

+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| Max_used_connections | 1001 |
+----------------------+-------+
1 row in set (0.00 sec)

3.通过命令生成杀进程脚本

root@localhost > select concat('KILL ',id,';') from information_schema.processlist where user=’sam' into outfile '/tmp/a.txt
脚本内容如下:

+------------------------+

| concat('KILL ',id,';') |
+------------------------+
| KILL 31964612; |
| KILL 31964609; |
| KILL 31964611; |
…...
| KILL 31966619; |
| KILL 31966620; |
+------------------------+
991 rows in set (0.02 sec)
root@localhost >

4.执行上面生成的KILL脚本

root@localhost > source /tmp/a.txt

Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
……
 
5.检查连接状况,恢复正常

root@localhost > show processlist;

6.修改Max_used_connections参数(注:记得要修改my.cnf文件,下次重启动后仍然有效)

mysql> set GLOBAL max_connections=2000;

Query OK, 0 rows affected (0.00 sec)

mysql> show variables like '%max_connections%';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 2000 |
+-----------------+-------+
1 row in set (0.00 sec)

此问题背后肯定存在着某些问题,不要只是一味地调大参数。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值