Loading
0

mysql innodb损坏修复方法shell批量处理

mysql innodb损坏修复方法shell批量处理,将脚本中的路径及相关信息改成自己的即可


    #!/bin/bash
    dbuser='root'
    dbpass='ssssss'
    mysqldata='/home/wddata/var'
    mycnf='/www/wdlinux/etc/my.cnf'
    mysql_e='/www/wdlinux/mysql/bin/mysql'
    mysqldump_e='/www/wdlinux/mysql/bin/mysqldump'
    mysqlbakpath="/home/bkmysql/$(date +%Y%m%d%H%M%S)"
    function stop_mysql(){
        service mysqld stop
        if [ $? -ne 0 ];then
        ps -e|grep mysql|awk '{print $1}'|xargs kill -9
        fi
    }
    mkdir -p $mysqlbakpath
    sed -i -e '/\[mysqld\]/a innodb_force_recovery=3' $mycnf
    stop_mysql
    service mysqld start
    #start dump innodb mysql
    if [ $? -eq 0 ];then
        cd $mysqldata
        ls *\/*.ibd -h|awk -F'/' '{print $1}'|uniq|grep -v 'mysql' > $mysqlbakpath/l.txt
        for i in `cat $mysqlbakpath/l.txt`
        do
            echo "dump $i"
            $mysqldump_e -f -u$dbuser -p$dbpass $i > $mysqlbakpath/$i.sql
        done
    fi
    #end dump innodb mysql
    #start bkup innodb mysql
    cd $mysqldata
    stop_mysql
    mv -f ibdata1 ib_logfile0 ib_logfile1 $mysqlbakpath
    for i in `cat $mysqlbakpath/l.txt`
    do
        mv -f $i $mysqlbakpath
    done
    #end bkup innodb mysql
    sed -i -e '/innodb_force_recovery=3/d' $mycnf
    service mysqld start
    #start Import mysql
    if [ $? -eq 0 ];then
        for i in `cat $mysqlbakpath/l.txt`
        do
            echo "recovey $i"
            $mysql_e -u$dbuser -p$dbpass -e "create database $i;"
            $mysql_e -u$dbuser -p$dbpass $i < $mysqlbakpath/$i.sql
        done
    fi
    #end Import mysql

声明:站长码字很辛苦啊,转载时请保留本声明及附带文章链接:http://blog.tag.gg/showinfo-13-35828-0.html
上一篇:宝塔mysql:ERROR! MySQL server PID file could not be found pid解决方法
下一篇:利用RAMDisk软件将内存转换为虚拟磁盘,可用于mysql临时目录等来提速