数据库要经常定期检测维护,发现错误,自动修复,适用于INNODB,MYISAM表,脚本如下:
#! /bin/bash
# use like this : mysql_check.sh db1 db2 db3 ...
# History:
# 2007/11/14 chentao 1.1
#----------------------------------------------------------------------
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
dbsum=$#
if [ "${dbsum}" -eq 0 ];then
echo "Error:no database chosed"
exit 1
fi
LogFile=/var/log/mysqlcheck.log
mysqlpath=/usr/local/mysql/bin/mysqlcheck
echo "------------------------------------------------------------------" >> $LogFile
echo "mysqlcheck start at [`date +"%Y-%m-%d %H:%M:%S"`]" >> $LogFile
for i in $*;do
$mysqlpath $i --check-only-changed --auto-repair --default-character-set=utf8 --silent -uroot -p123456 >> $LogFile
echo "check db $i done" >> $LogFile
done
echo "mysqlcheck end at [`date +"%Y-%m-%d %H:%M:%S"`]" >> $LogFile
阅读(2589) | 评论(0) | 转发(0) |