Recently, I checked the mysql database server log and found a Table corruption ERROR log, for example, 1207247: 30: 48 [ERROR]/data/soft/mysql/libexec/mysqld: Table '. /blog/wp_links 'ismarkedascrashedandlast (automatic ?) The repairfailed is normal after manual repair of the table, not a few
Recently, I checked the mysql database server log and found the ERROR log with Table damage. For example: 120724 7:30:48 [ERROR]/data/soft/mysql/libexec/mysqld: Table '. /blog/wp_links 'is marked as crashed and last (automatic ?) After the repair failed manually repairs the table, it is normal. After a few days, an error is found. So I wrote a script to automatically fix it. Logs are detected at a certain time. If such an error record exists, the error table is repaired to achieve automatic repair. To prevent repeated execution of error records in logs, after each log detection, the log file is cleared. There are actually many methods for this type of script, but this is only one of them. I haven't written the script for a long time, and I am confused about it. I hope you will come up with some mistakes, for more information, see.
#!/bin/sh DB_USER="root" DB_PASS="123456" DB_NAME="blog" LOG_PATH="/data/db/errlog.log" TIME=`date +%Y-%m-%d" "%H:%M:%S` TABLES=`/usr/bin/awk '/'"repair failed"'/ {print $6}' $LOG_PATH | sort -k1n | uniq -c | awk -F "'" '{print $2}' | awk -F '/' '{print $3}'` if [ -n "$TABLES" ] then for i in `/usr/bin/awk '/'"repair failed"'/ {print $6}' $LOG_PATH | sort -k1n | uniq -c | awk -F "'" '{print $2}' | awk -F '/' '{print $3}'` do /data/soft/mysql/bin/mysql -u$DB_USER -p$DB_PASS $DB_NAME -e "repair TABLE $i" > repair_$i if grep "OK" repair_$i >/dev/null then echo "$TIME repair TABLES $i successful!" else echo "$TIME repair TABLES $i Failed!" fi rm -rf repair_$i done else echo "There is no need to repair the table!" fi :>$LOG_PATH