Use the shell to check and repair the MySQL database table script _linux Shell

Source: Internet
Author: User

Copy Code code as follows:

#!/bin/sh
#code by Scpman
#功能: Review and repair MySQL database tables
#将此脚本加到定时中, when the script executes, it reads the library, lists all the tables to be repaired, and then timings to start the repair
#修复过程中将损坏的表记录下来, after the repair is completed, the damaged table will be sent to the mail notification.
fix_logs= '/tmp/fix.log '
User= '
Pass= '
Check_fix ()
{
Dblist= '/usr/bin/find/usr/dlm_db/mysql/-type D | Grep-ve "Logs|_[1-9]|*bak|test" | Sed-e "s#/usr/dlm_db/mysql/# #g" '
echo start ' Date ' > $fix _logs
For dbname in $dblist
Todo
Echo $dbname
For Tb_name in '/usr/bin/find/usr/dlm_db/mysql/$dbname-type F | Awk-f '/' {print $NF} ' | Awk-f '. ' ' {print $} ' | Sort-
U '
Todo
Mysql-u$user-p$pass $dbname <<fff>> $fix _logs
Check table $TB _name;
Repair table $TB _name;
FFF
Done
Done
echo ' Date ' done>> $fix _logs
}
Send_logs ()
{
msgip=10.0.7.44
ip= ' cat/etc/rc.conf | Grep-e "Ifconfig_[em1|bce1]" | awk ' {print ' IP: ' $} ' | Sed-n 1p '
fix_info= ' grep-re ' error|start|done ' $fix _logs '
/usr/bin/logger-p local1.info-h $MSGIP "The Services: $IP mysql_table_fix_info: $fix _info"
}
Check_fix
Send_logs

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.