Home >Database >Mysql Tutorial >How to Efficiently Convert MyISAM Tables to InnoDB?
Efficient Transformation of MyISAM Tables to InnoDB
MyISAM, although widely used in the past, has fallen behind InnoDB in terms of features and performance. For this reason, it may be desirable to convert your MyISAM tables to InnoDB. While you can manually alter each table individually, a more efficient approach exists for mass conversions.
Query to Identify MyISAM Tables
Begin by identifying all MyISAM tables in your database. Execute the following SQL statement:
SET @DATABASE_NAME = 'name_of_your_db'; SELECT CONCAT('ALTER TABLE `', table_name, '` ENGINE=InnoDB;') AS sql_statements FROM information_schema.tables AS tb WHERE table_schema = @DATABASE_NAME AND `ENGINE` = 'MyISAM' AND `TABLE_TYPE` = 'BASE TABLE' ORDER BY table_name DESC;
Converting Tables to InnoDB
Once you have the list of tables that need to be converted, copy the output from the SQL query and paste it into a new SQL statement. Run this new statement to execute the conversions:
<Copy-pasted SQL query>
This will efficiently convert all MyISAM tables in your database to InnoDB. Please note that tables that are already InnoDB will not be affected by this conversion process.
The above is the detailed content of How to Efficiently Convert MyISAM Tables to InnoDB?. For more information, please follow other related articles on the PHP Chinese website!