#!/bin/bash
pass="123456" #root's password
data_path="/home/mysql" #mysql's datadir
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 $f1.$_file_name >> /tmp/check_table.log
echo `date` >> /tmp/check_table.log
mysql -h 127.0.0.1 -u root -p$pass -e "check table "$f1.$_file_name 2>&1 >> /tmp/check_table.log #optimize table
done
cd ..
fi
fi
done