千家信息网

mysql 转换表的存储引擎脚本

发表于:2025-01-21 作者:千家信息网编辑
千家信息网最后更新 2025年01月21日,vi convert_tbale_engine.sh#!/bin/bashDB=testUSER=rootPASSWORD=123456HOST=192.168.1.10MYSQL_BIN=/usr/
千家信息网最后更新 2025年01月21日mysql 转换表的存储引擎脚本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
0