Linux下Mysql自动修复数据表的脚本

#!/bin/bash
#This script used by repair tables
mysql_host=localhost
mysql_user=root
mysql_pass=root
database=test

tables = $(mysql -h $mysql_host -u $mysql_user -p $mysql_pass $database -A -Bse "show tables")
for arg in $tables
do
check_status= $(mysql -h $mysql_host -u $mysql_user -p $mysql_pass $database -A -Bse "check table $arg" | awk '{ print $4 }')
if [ "$check_status" = "OK" ] then
echo "$arg is ok"
else
echo $(mysql -h $mysql_host -u $mysql_user -p $mysql_pass $database -A -Bse "repair table $arg")
fi
echo $(mysql -h $mysql_host -u $mysql_user -p $mysql_pass $database -A -Bse "optimize table $arg")
done

标签: Mysql