当前位置:Gxlcms > 数据库问题 > MySQL中kill所有慢查询进程和锁表进程

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

时间:2021-07-01 10:21:17 帮助过:153人阅读

#!/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 $1}`
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 $1}`
do
   mysqladmin kill ${lock}
done

 

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

标签:word   bsp   dmi   grep   进程   awk   gre   span   root   

人气教程排行