MySQL conversion table storage engine three ways

Source: Internet
Author: User

There may be scenarios where you need to change the table's storage engine, such as a table that stores logs if there are almost only inserts and a small number of select operations, it may be necessary to replace the storage engine with MyISAM for better insert performance. However, this article does not recommend mixing different storage engines in the same database.

1.ALTER TABLE

  The simplest way to modify a table from one storage engine to another is to execute the DDL statement, and the following statement changes the MyTable engine to InnoDB MyISAM:

Mysql>alter TABLE table_name Engine=myisam;

Execution effects such as:

    

This method of modification is tried with any storage engine, but it is important to note that if the data volume of the table is large and the execution time is very long, MySQL will copy the data from the original table into a new table, which may consume all of the system I/O capability during the replication and read the lock on the original table. Replacing the storage engine with a new table will lose all the features of the old storage engine, for example, after InnoDB is converted to MyISAM, all foreign keys will be lost.

2. Export and Import

  For better control of the conversion process, you can use the Mysqldump tool to export the data to a file, and then manually modify the storage Engine option engine for the CREATE TABLE statement, noting that the table name can be modified at the same time because the same table name cannot exist in the same database, but also note that The DROP TABLE statement will be added to the CREATE table by default in Mysqldump, which may result in data loss.

3.CREATE and SELECT

This approach is relative to the previous two efficient and safe features. Instead of exporting the entire table's data, you create a new table and then pass the insert .... SELECT syntax to import data.

  

  

  

If the amount of data is small, the above operation processing results are satisfactory. If you have a large amount of data, you can do it in batches, perform transactional commits for each piece of data, and avoid problems with large transactions, such as filtering by time or filtering the fragment submission based on the ID size.

START TRANSACTION;

INSERT into innodb_table SELECT * from mytable where ID between x and y (or create_time, etc.);

COMMIT;

MySQL conversion table storage engine three ways

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.