?
This document uses PHP Chinese website manual Release
一般批量修改MYSQL中某表的數(shù)據(jù)庫(kù)引擎可以利用官方工具mysql_convert_table_format來(lái)實(shí)現(xiàn), 這里指的是不使用其他工具僅用shell的方法來(lái)實(shí)現(xiàn)。(以下例子效果是將數(shù)據(jù)庫(kù)shop
中所有引擎不為InnoDB的表修改為使用InnoDB引擎)[ 查看表引擎的語(yǔ)句:show create table tableName;
],其實(shí)核心關(guān)鍵點(diǎn)是這條語(yǔ)句:
alert table tableName engine=innodb;
下面開(kāi)始修改:
mysqldump -uroot -p******** shop > shop20160505.sql
mysql -uroot -p******** -e 'create database shop_to_innodb charset utf8'; mysql -uroot -p******** shop_to_innodb < shop20160505.sql
mysql -uroot -p******** -e "show table status from shop_to_innodb where Engine <> 'InnoDB' \G"|grep Name|awk '{print "alter table "$2" engine=innodb;";}' > mysql_change_to_innodb.txt
上面的語(yǔ)句在命令行中執(zhí)行得到
mysql_change_to_innodb.txt
文件(包含了shop_to_innodb庫(kù)中所有引擎不為InnoDB的改變語(yǔ)句)。
使用vim命令
或者cat命令
查看 mysql_change_to_innodb.txt
文件,檢查是否為自己要修改的內(nèi)容。
alter table a engine=innodb; alter table b engine=innodb; alter table category engine=innodb; alter table ecs_account_log engine=innodb; alter table ecs_ad engine=innodb; alter table ecs_ad_custom engine=innodb; alter table ecs_ad_position engine=innodb; alter table ecs_admin_action engine=innodb; alter table ecs_admin_log engine=innodb; alter table ecs_admin_message engine=innodb; alter table ecs_admin_user engine=innodb; alter table ecs_adsense engine=innodb; alter table ecs_affiliate_log engine=innodb; alter table ecs_agency engine=innodb; alter table ecs_area_region engine=innodb; alter table ecs_article engine=innodb; alter table ecs_article_cat engine=innodb; alter table ecs_attribute engine=innodb; alter table ecs_auction_log engine=innodb; alter table ecs_auto_manage engine=innodb; alter table ecs_back_goods engine=innodb; alter table ecs_back_order engine=innodb; alter table ecs_bonus_type engine=innodb; alter table ecs_booking_goods engine=innodb; alter table ecs_brand engine=innodb; alter table ecs_card engine=innodb; alter table ecs_cart engine=innodb; ... ...
如果沒(méi)用問(wèn)題我們可以接著執(zhí)行下面的語(yǔ)句。
mysql -uroot -p******** shop_to_innodb < mysql_change_to_innodb.txt
如果數(shù)據(jù)庫(kù)非常大可能要等一段時(shí)間