Timed MySQL timeout using Linux Shell scripts

Source: Internet
Author: User

Recently, I just entered a new company and took over a site here. The architecture design of this site is not reasonable, so MySQL is always under great pressure, the Locked process often times out, so a Linux Shell script is compiled to kill these processes at regular intervals.
The script is as follows:
Copy codeThe Code is as follows:
#! /Bin/bash
Mysql_pwd = "xxxxxx" # mysql root Password
Mysql_exec = "/usr/local/mysql/bin/mysql"
Tmp_dir = "/tmp"
File_sh = "$ tmp_dir/mysql_kill_locked.sh"
File_tmp = "$ tmp_dir/mysql_kill_locked.tmp"
File_log = "$ tmp_dir/mysql_kill_locked.log" # log
$ Mysql_exec-uroot-p $ mysql_pwd-e "show processlist" | grep-I "Locked"> $ file_tmp
Cat $ file_tmp> $ file_log
For line in 'cat $ file_tmp | awk '{print $1 }''
Do
Echo "$ mysql_exec-uroot-p $ mysql_pwd-e" kill $ line "" >>$ file_sh
Done
Chmod + x $ file_sh
Sh $ file_sh # execute a temporary script
> $ File_sh # Clear the temporary script
 
Finally, add the script to crontab and execute it regularly.

Related Article

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.