Home > Database > Mysql Tutorial > body text

MySQL实现批量检查表并进行repair与optimize的方法_MySQL

PHP中文网
Release: 2016-05-27 13:44:36
Original
1039 people have browsed it

本文实例讲述了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
Copy after login

也可以使用mysqlcheck命令,此方法可以在检查表并自动修复损坏的表,不过该过程比较耗时。

 以上就是MySQL实现批量检查表并进行repair与optimize的方法_MySQL的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!