[root@HE1 ~]# catconvert_Storage_Engine.sh

#/bin/bash
#FileName:Convert_Storage_Engine.sh
#Desc:Conversion ofa MySQL tables to other storage engines
#Create By:helei
#Date:201i6/03/18
DB=hexiaodb
USER=root
PASSWD=MANAGER
HOST=192.168.1.48
MYSQL_BIN=/usr/local/mysql/bin
S_ENGINE=MyISAM
D_ENGINE=InnoDB
#echo "EnterMySQL bin path:"
#read MYSQL_BIN
#echo "EnterHost:"
#read HOST
#echo "EnterUesr:"
#read USER
#echo "EnterPassword:"
#read PASSWD
#echo "Enter DBname :"
#read DB
#echo "Enterthe original engine:"
#read S_ENGINE
#echo "Enterthe new engine:"
#read D_ENGINE
$MYSQL_BIN/mysql-h$HOST -u$USER -p$PASSWD $DB -e "select TABLE_NAME frominformation_schema.TABLES where TABLE_SCHEMA='"$DB"' andENGINE='"$S_ENGINE"';" | grep -v "TABLE_NAME">tables.txt
for t_name in `cattables.txt`
do
    echo "Starting convert table$t_name......"
    sleep 1
    $MYSQL_BIN/mysql -h$HOST -u$USER -p$PASSWD$DB -e "alter table $t_name engine='"$D_ENGINE"'"
    if [ $? -eq 0 ]
    then
        echo "Convert table $t_nameended." >>con_table.log
        sleep 1
    else
        echo "Convert failed!">> con_table.log
    fi
done


本文出自 “岁伏” 博客,请务必保留此出处http://suifu.blog.51cto.com/9167728/1753996

posted on 2016-08-19 17:13  岁伏  阅读(287)  评论(0编辑  收藏  举报