Home >Database >Mysql Tutorial >MySQL批量检查表的脚本_MySQL

MySQL批量检查表的脚本_MySQL

WBOY
WBOYOriginal
2016-06-01 13:51:21997browse

在不知道mysqlcheck之前,移动了一台服务器上的数据库,到另一台服务器上,想看看哪个表被损坏了,不想在命令行一个一个执行,下面是我写的脚本

#!/bin/bash<br><br>pass="123456" #root's password<br>data_path="/home/mysql" #mysql's datadir<br><br>cd $data_path<br>for f1 in $(ls)<br>do<br>    if [ -d $f1 ];then<br>        if [ "mysql" != "$f1" -a "test" != "$f1" ];then #in<br>            cd $f1<br>            echo "I'm in "$f1<br>            for f2 in $(ls *.frm)<br>            do<br>                _file_name=${f2%.frm}<br>                echo $f1.$_file_name >> /tmp/check_table.log<br>                echo `date` >> /tmp/check_table.log<br>                mysql -h 127.0.0.1 -u root -p$pass -e "check table "$f1.$_file_name 2>&1 >> /tmp/check_table.log #optimize table<br>            done<br>            cd ..<br>        fi<br>    fi<br>done
Statement:
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