[英]MYSQL query Alter table engine only if engine not innodb
I would like to run one query that alter table's engine (ALTER TABLE table1
ENGINE = INNODB) only if the current engine is not INNODB. 我想只在当前引擎不是INNODB的情况下运行一个更改表引擎的查询(ALTER TABLE table1
ENGINE = INNODB)。
How can I do that? 我怎样才能做到这一点?
Update: I got a case of a query trying to alter the table's engine while its already innodb. 更新:我遇到了一个查询,试图在表已为innodb时更改表的引擎。
You can use 您可以使用
ALTER TABLE t ENGINE = InnoDB;
You can use this query. 您可以使用此查询。 If db engine already InnoDB then nothing will happen. 如果数据库引擎已经是InnoDB,那么什么也不会发生。 Output will be 输出将是
MySQL returned an empty result set (i.e. zero rows)
if engine not in InnoDB, then it will convert to InnoDB. 如果引擎不在InnoDB中,则它将转换为InnoDB。
The command has no effect if the table is already on InnoDB
. 如果表已经在InnoDB
上,则该命令无效。
You can query the table engine from information_schema: 您可以从information_schema查询表引擎:
SELECT `ENGINE` from `information_schema`.`TABLES`
WHERE `TABLE_SCHEMA`='my_schema' AND `TABLE_NAME`='table1';
http://mysql.rjweb.org/doc.php/myisam2innodb#generating_alters provides several tips about converting from MyISAM to InnoDB, including: http://mysql.rjweb.org/doc.php/myisam2innodb#generating_alters提供了一些有关从MyISAM转换为InnoDB的技巧,包括:
To generate all the ALTERs to convert all the MyISAM tables to InnoDB: 生成所有ALTER以将所有MyISAM表转换为InnoDB:
SELECT CONCAT('USE ', table_schema, '; ALTER TABLE ', table_name, ' ENGINE=InnoDB;')
FROM information_schema.tables
WHERE engine = 'MyISAM'
AND table_schema NOT IN ('mysql', 'information_schema', 'performance_schema');
Then copy and paste the output into the mysql commandline tool. 然后将输出复制并粘贴到mysql命令行工具中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.