01
02
03
04
05
06
echo
-e
"此脚本的主要用途是检测mysql服务器上所有的数据库或者单独数据库中的坏表\n\n"
07
pass=123456
08
name=root
09
10
read
-p
"输入mysql存储路径: "
choose
11
data_path=$choose
12
unset
choose
13
14
read
-p
"请输入mysql命令路径: "
mysql_version
15
16
read
-p
"请选择是检查服务器上所有数据库还是指定的数据库 1:检查全部数据库 2:只检查指定数据库: "
choose
17
if
[ $choose == 1 ];
then
18
cd
$data_path
19
for
directory_list
in
$(
ls
)
20
do
21
if
[ -d $directory_list ];
then
22
if
[
"mysql"
!=
"${directory_list}"
-a
"test"
!=
"${directory_list}"
];
then
23
cd
${directory_list}
24
echo
"当前检查数据库为:"
${directory_list}
25
for
file_list
in
$(
ls
*.frm)
26
do
27
_file_name=${file_list%.frm}
28
echo
-e
"\n"
>> /tmp/check_table_all.log
29
${mysql_version} -h 127.0.0.1 -u${name} -p${pass} -e
"check table "
${directory_list}.${_file_name} 2>&1 >> /tmp/check_table_all.log
30
done
31
cd
..
32
fi
33
fi
34
done
35
cat
/tmp/check_table_all.log |
grep
"Table is marked as crashed"
> /tmp/check_table_repair.log
36
repair_count_all=`
awk
'END{print NR}'
/tmp/check_table_repair.log `
37
echo
-e
"所有数据库用有${repair_count_all}张表需要修复!"
38
more
/tmp/check_table_repair.log
39
else
40
read
-p
"请输入要检查的数据库名称: "
db_name
41
cd
${data_path}/${db_name}
42
for
file_list
in
$(
ls
*.frm)
43
do
44
_file_name=${file_list%.frm}
45
echo
-e
"\n"
>> /tmp/check_${db_name}.log
46
${mysql_version} -h 127.0.0.1 -u${name} -p${pass} -e
"check table "
${db_name}.$_file_name 2>&1 >> /tmp/check_${db_name}.log
47
done
48
cat
/tmp/check_${db_name}.log |
grep
"Table is marked as crashed"
> /tmp/check_${db_name}_Repair.log
49
repair_count=`
awk
'END{print NR}'
/tmp/check_${db_name}_Repair.log`
50
echo
-e
"${db_name}中共有${repair_count}个表需要修复!\n "
51
more
/tmp/check_${db_name}_Repair.log
52
fi