mysql 轉換表的儲存引擎指令碼

abin1703發表於2016-05-11
vi convert_tbale_engine.sh
#!/bin/bash
DB=test
USER=root
PASSWORD=123456
HOST=192.168.1.10
MYSQL_BIN=/usr/local/bin
S_ENGINE=MyISAM
D_ENGINE=InnoDB
$MYSQL_BIN/mysql -h$HOST -u$USER -p$PASSWORD $DB -s -e "select table_name from infomation_schem.table where table_schema='test' and engine='myisam'"|grep -v "table_name" >table.txt
for t_name in `cat table.txt`
do 
echo "Staring convert table $t_name..."
sleep 1
$MYSQL_BIN/mysql -h$HOST -u$USER -p$PASSWORD $DB -e "alter table $t_name engine=$D_ENGINE"
if [ $? -eq 0 ];then
echo "Convert table $t_name ended ">con_table.log
sleep 1
else
echo "Convert tbale $t_name failed ">con_table.log
fi
done

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30345407/viewspace-2097857/,如需轉載,請註明出處,否則將追究法律責任。

相關文章