shell命令批量殺死MySQL資料庫連接進程

(1)將所有的MySQL連接進程殺掉
for i in `mysql -uroot -pzhangyun -Bse "show processlist" | grep -v "show processlist" | awk '{print $1}'`
do
mysql -uroot -pzhangyun -e "kill $i"
done

註:這裡將自身命令的show processlist進程過濾掉

(2)刪除指定用戶的連接進程
for i in `mysql -uroot -pzhangyun -se "show processlist" | grep -v "show processlist" | awk '{if($2=="zhangyun")print $1}'`
do
mysql -uroot -pzhangyun -e "kill $i"
done

You May Also Like