批量kill mysql中运行时间长的sql

mysql>select concat('KILL ',id,';') from information_schema.processlist where user='service' and info like 'SELECT t2.* FROM  t_ec_order t1,t_ec_insurance t2%' into outfile '/tmp/a.txt'; 

mysql>source /tmp/a.txt 

1、通过information_schema.processlist表中的连接信息生成需要处理掉的MySQL连接的语句临时文件,然后执行临时文件中生成的指令 

mysql> select concat('KILL ',id,';') from information_schema.processlist where user='root'; 

+------------------------+ 
| concat('KILL ',id,';') |
+------------------------+ 
| KILL 3101;             |
| KILL 2946;             |
+------------------------+ 

2 rows in set (0.00 sec) 

mysql>select concat('KILL ',id,';') from information_schema.processlist where user='root' into outfile '/tmp/a.txt'; 
Query OK, 2 rows affected (0.00 sec) 

mysql>source /tmp/a.txt; 
Query OK, 0 rows affected (0.00 sec) 

2、杀掉当前所有的MySQL连接 
mysqladmin -uroot -p processlist|awk -F "|" '{print $2}'|xargs -n 1 mysqladmin -uroot -p kill 

杀掉指定用户运行的连接,这里为Mike 
mysqladmin -uroot -p processlist|awk -F "|" '{if($3 == "Mike")print $2}'|xargs -n 1 mysqladmin -uroot -p kill 

3、通过SHEL脚本实现 
#杀掉锁定的MySQL连接 

for id in `mysqladmin processlist|grep -i locked|awk '{print $1}'` 
do 
 mysqladmin kill ${id} 
done 

4、通过Maatkit工具集中提供的mk-kill命令进行 

#杀掉超过60秒的sql 
mk-kill -busy-time 60 -kill 

#如果你想先不杀,先看看有哪些sql运行超过60秒 
mk-kill -busy-time 60 -print 

#如果你想杀掉,同时输出杀掉了哪些进程 
mk-kill -busy-time 60 -print –kill 

5、查询session分布
select SUBSTRING_INDEX(host,':',1) as ip ,user,COMMAND, count(*) from information_schema.processlist group by ip,user,COMMAND;

  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Running Sun丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值