我知道我可以单独发出一个alter表,将表存储从MyISAM更改为InnoDB。

我想知道是否有一种方法可以快速将它们全部更改为InnoDB?


当前回答

cd / var / lib / mysql / DBNAME

Ls | grep ".frm" | cut -d"."-f1 | xargs -I{} -n1 mysql -D DBNAME -e "alter table {} ENGINE=INNODB;"-uroot -pXXXXX

其他回答

您可以用您最喜欢的脚本语言编写一个脚本来完成它。该脚本将执行以下操作:

Issue显示满表。对于返回的每一行,检查第二列是否显示为“BASE TABLE”而不是“VIEW”。如果它不是'VIEW',发出适当的ALTER TABLE命令。

遵循步骤:

Use MySql commands as follows, for converting to InnoDB (ALTER TABLE t1 ENGINE = InnoDB) or (ALTER TABLE t1 ENGINE = MyISAM) for MyISAM (You should do this for each individual tables, t1 is for the table name.). Write a script that loops on all tables and run the alter command Use an already available script to handle that: https://github.com/rafihaidari/convert-mysql-tables-storage-engine Try this SQL to Get all info will get all the tables information then you can change all the table from isam to InnoDB SELECT CONCAT('ALTER TABLE ',TABLE_NAME,' ENGINE=InnoDB;') FROM INFORMATION_SCHEMA.TABLES WHERE ENGINE='MyISAM' AND table_schema = 'your_DB_Name';

这很简单。只有两步。

复制,粘贴并运行: SET @DATABASE_NAME = ' name_your_db '; SELECT CONCAT('ALTER TABLE ", table_name, ' ENGINE=InnoDB;') AS sql_statements FROM information_schema。TABLE AS tb WHERE ' ENGINE ' = 'MyISAM' AND ' TABLE_TYPE ' = 'BASE TABLE'

(复制粘贴所有结果在SQL选项卡)

将所有结果复制到SQL选项卡并在下面一行中粘贴。 开始事务; 提交;

例如:

START TRANSACTION;
ALTER TABLE `admin_files` ENGINE=InnoDB;
COMMIT;

它还没有被提及,所以我将为后人写下来:

如果你在DB服务器之间迁移(或者有其他原因你需要转储和重新加载你的dta),你可以修改mysqldump的输出:

mysqldump --no-data DBNAME | sed 's/ENGINE=MyISAM/ENGINE=InnoDB/' > my_schema.sql;
mysqldump --no-create-info DBNAME > my_data.sql;

然后再次加载:

mysql DBNAME < my_schema.sql && mysql DBNAME < my_data.sql

(此外,根据我有限的经验,这可能是一个比“实时”修改表快得多的过程。这可能取决于数据和索引的类型。)

一行:

 mysql -u root -p dbName -e 
 "show table status where Engine='MyISAM';" | awk 
 'NR>1 {print "ALTER TABLE "$1" ENGINE = InnoDB;"}'  | 
  mysql -u root -p dbName