具體步驟:
1.輸入MySQL的root密碼
2.輸入MySQL數據文件的全路徑
3.優化日志是/tmp/optimize.log
4.剩下的就不用管了:)
#!/bin/sh
#Author: sunss
#Date: 2010-11-11
#
echo "Please input MySQL's root passWord!"
read pass
echo "Please input your MySQL's data directory!"
read data_path
if [ -z $data_path ];then
echo "You didn't do what I'v told you!"
exit 1
fi
if [ ! -d $data_path ];then
echo $data_path" isn't a directory!"
exit 1
fi
cd $data_path
for f1 in $(ls)
do
if [ -d $f1 ];then
if [ "MySQL" != "$f1" -a "test" != "$f1" ];then #in
cd $f1
echo "I'm in "$f1
for f2 in $(ls *.frm)
do
_file_name=${f2%.frm}
echo `date` >> /tmp/optimize.log
MySQL -u root -p$pass -e "optimize table "$f1.$_file_name 2>&1 >> /tmp/optimize.log #optimize table
done
cd ..
fi
fi
done
一般優化表後的提示是OK,如下:
Table Op Msg_type Msg_text
dashi.hx_focus optimize status OK
如果在日志裡發現:
2010年 11月 11日 星期四 19:13:18 CST
Table Op Msg_type Msg_text
tool.re_keyWord optimize status Table is already up to date
但這個表發現提示:Table is already up to date 。
查了下:Table is already up to date means that the storage engine for the table indicated that there was no need to check the table.
這個表明修復的挺好,不需要再檢查了