MySQL中kill所有慢查询进程和锁表进程
Posted fansik
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 $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所有慢查询进程和锁表进程的主要内容,如果未能解决你的问题,请参考以下文章