命令行批量kill mysql 任务
最近有定时kill掉某些条件的mysql查询需求,记录一下
实现原理:
利用processlist获取所有的查询
然后用awk处理查询结果,输出查询id
接着用xargs批量处理kill id
#!/bin/bash while [ true ] do /bin/sleep 60 date mysqladmin -hhost -uusername -ppassed -Pport processlist |awk -F "|" '{if($8 == " Copying to tmp table ")print $2}' |xargs -n 1 mysqladmin -hhost -uusername -ppassed -Pport kill mysqladmin -hhost -uusername -ppassed -Pport processlist |awk -F "|" '{if($8 == " Waiting for table metadata lock ")print $2}' |xargs -n 1 mysqladmin -hhost -uusername -ppassed -Pport kill done
p