0514-86177077
9:00-17:00(工作日)
本文介紹mysql定時批量檢查表repair和優化表optimize table的shell腳本,對于MySQL數據庫的定期維護相當有用!如下所示:
#!/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 nbsp;"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 nbsp;"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 nbsp;"optimize table $table_name") fi done
標簽:通遼 南充 延邊 朝陽 雅安 西藏 青島 隨州
上一篇:Linux下實現SNMP一鍵安裝的Shell腳本
下一篇:centos/rhel下實現nginx自啟動腳本實例
Copyright ? 1999-2012 誠信 合法 規范的巨人網絡通訊始建于2005年
蘇ICP備15040257號-8