自动修复数据库中所有的库中的所有的表
#!/bin/bash
#mysqlautorepaird
#description: auto repair crash table
#Can fix almost anything except unique keys that aren't unique.
echo "Starting mysqlautorepaird"
PACKAGE='repair database'
MYSQLCHECK='/usr/bin/mysqlcheck'
DATADIR=`cat /etc/mysql/my.cnf | grep datadir | awk '{print $3}'`
DATABASES=`ls -d ${DATADIR}/*/ | awk -F'/' '{print $(NF-1)}'`
for DATABASE in ${DATABASES}
do
${MYSQLCHECK} -r ${DATABASE}
done
这个脚本非常的简单,但是实现的功能是非常好的,可以把它加入到计划任务中,每天或每个月自动修复数据库,这样用户在读取或操作数据库的时候就不会出现 table is crashed try to repair it.这种东西了。
浙公网安备 33010602011771号