Script for automatically clearing MYSQL Lock process the database server suddenly surges in the number of processes in a certain period of time recently, resulting in the database server to die, according to log query, the reason is that a large number of Mysql Lock processes cause a high number of server processes. I wrote a script and checked every minute. If the load is too high, some Lock processes will be killed. The following script can be used to complete other tasks. High server load is dangerous and may cause the entire service to go down. Although killing some processes may cause some exceptions to some user access, it is better than server downtime. Cat killmysqlprocess. sh submit www.2cto.com #! /Bin/bash #*/1 *****/usr/local/src/killmysqlprocess. sh backdir = "/usr/local/logs/" logfile = "cms_mysql_killprocess _ $ (date +" % Y % m % d "). log "mysqlbindir ="/usr/local/mysql/bin/"# use commond 'vmstat' get proc num pronum = 'vmstat | awk-F" "'{if (NR = = 3) print $1} 'vmstat. tmp '# if pronum less 20, nothing to do .......... exit if [$ pronum-lt 20]; then exitfi # it's here more than 20, run kill mysql Lock process $ {mysqlbindir} mysql-e "show full processlist"> processlist. tmp # get Lock mysql process idawk-F "" '/Locked/{print $1}' processlist. tmp> looplock. tmp sleep 5 www.2cto.com for line in 'cat looplock. tmp 'do/usr/local/mysql/bin/mysql-e "kill $ {line}" done rm-f looplock. tmp # write kill log echo $ (date + "% Y-% m-% d % H: % M: % S")> $ {backdir }$ {logfile} cat processlist. tmp >$ {backdir }$ {logfile} rm-f processlist. tmp