批量杀死MySQL连接的四种方法详解
方法一
通过information_schema.processlist表中的连接信息生成需要处理掉的MySQL连接的语句临时文件,然后执行临时文件中生成的指令。
mysql>selectconcat('KILL',id,';')frominformation_schema.processlistwhereuser='root';
+------------------------+
|concat('KILL',id,';')|
+------------------------+
|KILL3101; |
|KILL2946; |
+------------------------+
2rowsinset(0.00sec)
mysql>selectconcat('KILL',id,';')frominformation_schema.processlistwhereuser='root'intooutfile'/tmp/a.txt';
QueryOK,2rowsaffected(0.00sec)
mysql>source/tmp/a.txt;
QueryOK,0rowsaffected(0.00sec)
方法二
杀掉当前所有的MySQL连接
mysqladmin-uroot-pprocesslist|awk-F"|"'{print$2}'|xargs-n1mysqladmin-uroot-pkill
杀掉指定用户运行的连接,这里为Mike
mysqladmin-uroot-pprocesslist|awk-F"|"'{if($3=="Mike")print$2}'|xargs-n1mysqladmin-uroot-pkill
方法三
通过SHEL脚本实现
#杀掉锁定的MySQL连接
foridin`mysqladminprocesslist|grep-ilocked|awk'{print$1}'`
do
mysqladminkill${id}
done
方法四
通过Maatkit工具集中提供的mk-kill命令进行
#杀掉超过60秒的sql mk-kill-busy-time60-kill #如果你想先不杀,先看看有哪些sql运行超过60秒 mk-kill-busy-time60-print #如果你想杀掉,同时输出杀掉了哪些进程 mk-kill-busy-time60-print–kill
mk-kill更多用法可参考:
http://www.maatkit.org/doc/mk-kill.html
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下