Script for automatically clearing MYSQL Lock Process

Source: Internet
Author: User


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
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.