我们经常需要使用show processlist命令,然后kill掉Sleep进程防止堵塞数据库,这里提供一个脚本可以批量杀进程方便使用.
#!/bin/sh
n=`/usr/local/mysql/bin/mysql -uxxxx -pxxxx -S/dev/shm/mysql.sock -e "show full processlist\G" | grep -i Sleep | wc -l`
#date=`date +%Y%m%d\[%H:%M:%S]`
#echo $n
#if [ "$n" -gt 10 ]
#then
for i in `/usr/local/mysql/bin/mysqladmin -uxxxx -pxxxx -S/dev/shm/mysql.sock processlist | grep -i Sleep | awk '{print $2}'`
do
/usr/local/mysql/bin/mysqladmin -uxxxx -pxxxx -S/dev/shm/mysql.sock kill $i
done
echo "sleep is too many i killed it" >> /tmp/sleep.log
echo "$date : $n" >> /tmp/sleep.log
#fi
阅读(5336) | 评论(0) | 转发(0) |