MySQL中kill所有慢查询进程和锁表进程

1、kill所有慢查询进程:

#!/bin/bash
mysql -uroot -pMy_Password -e "show processlist" | grep -i "Query" > slow_query.log

for query in `cat slow_query.log | awk '{print $1}'`
do
   echo "kill $query;" > kill_slow_query.sql
done

登录mysql,执行:

mysql> source kill_slow_query.sql

或者:

#!/bin/bash
for query in `mysqladmin -uroot -pMy_Password processlist | grep -i 'Query' | awk '{print $2}'`
do
   mysqladmin kill ${query}
done

2、kill所有死锁进程:

#!/bin/bash
mysql -uroot -pMy_Password -e "show processlist" | grep -i "Locked" > locked.log

for lock in `cat locked.log | awk '{print $1}'`
do
   echo "kill $lock;" > kill_locked.sql
done

登录mysql,执行:

mysql> source kill_locked.sql

或者:

#!/bin/bash
for lock in `mysqladmin -uroot -pMy_Password processlist | grep -i 'Locked' | awk '{print $2}'`
do
   mysqladmin kill ${lock}
done

 

posted @ 2017-06-20 16:23  fansik  阅读(1162)  评论(0编辑  收藏  举报