Use Linux shell script to handle Mysql timeout _mysql

Source: Internet
Author: User
Recently, I have just entered a new company, and took over a site here, because the site's architectural design is not reasonable, resulting in the pressure of MySQL is always very large, often the locked process of time out, so wrote a section of Linux shell script to kill these processes regularly.
The script is as follows:
Copy Code code as follows:

#!/bin/bash
Mysql_pwd= "XXXXXX" #mysql的root密码
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" #日志
$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 '} '
Todo
echo "$mysql _exec-uroot-p$mysql_pwd-e" Kill $line "" >> $file _sh
Done
chmod +x $file _sh
SH $file _sh #执行临时脚本
> $file _sh #清空临时脚本

Finally, the script is added to the crontab, and can be executed 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.