MySQL完成批量檢討表並停止repair與optimize的辦法。本站提示廣大學習愛好者:(MySQL完成批量檢討表並停止repair與optimize的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是MySQL完成批量檢討表並停止repair與optimize的辦法正文
本文實例講述了MySQL完成批量檢討表並停止repair與optimize的辦法。分享給年夜家供年夜家參考,詳細以下:
以下是shell的參考代碼:
#!/bin/bash host_name=192.168.0.123 user_name=xiaomo user_pwd=my_pwd 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 $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 # 優化表,可進步機能 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
也能夠應用mysqlcheck敕令,此辦法可以在檢討表並主動修復破壞的表,不外該進程比擬耗時。
願望本文所述對年夜家MySQL數據庫計有所贊助。