批量修改Mysql表引擎为InnoDB的方法

2020-07-2817:44:04数据库教程Comments1,771 views字数 1959阅读模式

批量修改MYSQL中某表的数据库引擎可以利用官方工具mysql_convert_table_format来实现, 这里指的是不使用其他工具仅用shell的方法来实现。(以下例子效果是将数据库shop中所有引擎不为InnoDB的表修改为使用InnoDB引擎)[ 查看表引擎的语句:show create table tableName; ],其实核心关键点是这条语句:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19905.html

alert table tableName engine=innodb;

下面开始修改:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19905.html

备份数据库

在命令行下运行得到备份SQL

mysqldump -uroot -p******** shop > shop20160505.sql

在命令行建立一个测试数据库并导入SQL

mysql -uroot -p******** -e 'create database shop_to_innodb charset utf8';
mysql -uroot -p******** shop_to_innodb < shop20160505.sql

shell获取需要更换表引擎

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

上面的语句在命令行中执行得到 mysql_change_to_innodb.txt 文件(包含了shop_to_innodb库中所有引擎不为InnoDB的改变语句)。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19905.html

查看导出的修改语句

使用vim命令或者cat命令查看 mysql_change_to_innodb.txt 文件,检查是否为自己要修改的内容。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19905.html

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;
... ...

执行修改语句

如果没用问题我们可以接着执行下面的语句。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19905.html

mysql -uroot -p******** shop_to_innodb < mysql_change_to_innodb.txt

如果数据库非常大可能要等一段时间文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19905.html

文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19905.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/sjk/19905.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定