加入收藏 | 设为首页 | 会员中心 | 我要投稿 云计算网_泰州站长网 (http://www.0523zz.com/)- 视觉智能、AI应用、CDN、行业物联网、智能数字人!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

连接数过多,应急处理方法

发布时间:2022-04-01 23:03:35 所属栏目:MySql教程 来源:互联网
导读:连接数过多,应急处理方法: 一、问题描述 今天突然接到个问题,网页报错:503 Service Temporarily Unavailable。经过查询发现是某个用户的连接超级多,已经将数据库连接占满。处理方案,即时杀掉堵塞的进程,之后可以扩大max_connections参数。 二、处理
        连接数过多,应急处理方法:

一、问题描述
        今天突然接到个问题,网页报错:503 Service Temporarily Unavailable。经过查询发现是某个用户的连接超级多,已经将数据库连接占满。处理方案,即时杀掉堵塞的进程,之后可以扩大max_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)

(编辑:云计算网_泰州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读