MySQL implements a batch checklist and repair and optimize, rechecking roptimize
This example describes how to implement a batch checklist and repair and optimize in MySQL. We will share this with you for your reference. The details are as follows:
The following is the shell reference code:
#! /Bin/bashhost_name = 192.168.0.123user _ name = xiaomouser_pwd = my_pwd database = databases = truetables = $ (mysql-h $ host_name-u $ user_name-p $ user_pwd $ database-A-Bse" show tables ") for table_name in $ tablesdo check_result = $ (mysql-h $ host_name-u $ user_name-p $ user_pwd $ database-A-Bse "check table $ table_name" | awk '{print $4 }') if ["$ check_result" = "OK"] then echo "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, 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") fidone
You can also use the mysqlcheck command. This method can be used to check the table and automatically repair damaged tables, but this process is time-consuming.