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.
How can I do that?
Update: I got a case of a query trying to alter the table's engine while its already innodb.
You can use
ALTER TABLE t ENGINE = InnoDB;
You can use this query. If db engine already InnoDB then nothing will happen. Output will be
MySQL returned an empty result set (i.e. zero rows)
if engine not in InnoDB, then it will convert to InnoDB.
The command has no effect if the table is already on InnoDB
.
You can query the table engine from 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:
To generate all the ALTERs to convert all the MyISAM tables to 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.