MySQL批量转换为InnoDB引擎脚本

批量将MyISAM转换成InnoDB:

#!/bin/bash

user=root
password=rootpassword
database=testdb

tables=$(echo "show tables" | mysql -u$user -p$password $database)

for table in $tables;
do
    #echo $table
    is_myiasm=$(echo "show create table $table" | mysql -u$user -p$password $database | grep "ENGINE=MyISAM")
    if [ -n "$is_myiasm" ];
    then
        echo "$table is MyISAM"
        echo "alter table $table ENGINE=InnoDB" | mysql -u$user -p$password $database
    fi
done