检验数据库表是否正常

来源:互联网 发布:窗帘定高和定宽算法 编辑:程序博客网 时间:2024/05/16 07:43
#!/bin/sh
mysql_in=/mnt/data/mysql-arm
mysql_bin=${mysql_in}/bin/mysql
mysql_user=root
check_database()
{
list=`mysql -uroot -e "use dispatch_web;show tables"`
for i in $list
do
if [ "$i" = "Tables_in_dispatch_web" ]
then
echo $i
else
var=`mysql -uroot -e "use dispatch_web;select count(*) from ${i}"|grep ERROR`
echo "var=${var}"
if [ -n "$var" ]
then
mysql -uroot -e "use dispatch_web;REPAIR TABLE ${i} USE_FRM"
echo "repaired ${i}"
else
echo  "${i} is normal"
fi
fi
done
}

###############################################################################
check_database
0 0