This article describes the MySQL regular batch check table repair and optimization table optimize the shell script, for MySQL database maintenance is very useful! As shown below:
#!/bin/bash
host_name=192.168.0.123
user_name=jincon.com
user_pwd=jincon.com
database=my_db_ Name
need_optmize_table=true
tables=$ (mysql-h$host_name-u$user_name-p$user_pwd $database-A-bse "show Tables ") for
table_name in $tables
do
check_result=$ (mysql-h$host_name-u$user_name-p$user_pwd $ Database-a-bse
"Check table $table _name" | awk ' {print $} ')
if ["$check _result" = "OK"]
then
E Cho "It ' s no need to repair table $table _name"
else
echo $ (mysql-h$host_name-u$user_name-p$user_pwd $database -A-BSE
"Repair table $table _name")
fi
# optimization table, can be advanced high performance
if [$need _optmize_table = true]
then
echo $ (mysql-h$host_name-u$user_name-p$user_pwd $database-A-bse
"optimize table $table _name")
fi
Done