Question Overflow
Question Overflow

Reputation: 11275

Why does converting from MyISAM to InnoDB takes forever?

I wanted to convert a 700MB table from MyISAM to InnoDB with the following command:

ALTER TABLE table_name ENGINE = InnoDB;

I am not sure why it took forever (It did not complete, I killed the query after an hour of waiting). I observed that my memory usage climbed to 60% and plateau off. I am suspecting that adjusting some parameter may help, but I wonder which one.

Upvotes: 0

Views: 4228

Answers (2)

unutbu
unutbu

Reputation: 880987

There is a discussion of issues regarding conversion to InnoDB in the MySQL docs.

Here are some highlights/quotes:

  • If your table has unique constraints, then turn off unique checks first:

    SET unique_checks=0;
    ALTER TABLE table_name ENGINE = InnoDB;    
    SET unique_checks=1;
    
  • "To get better control over the insertion process, it might be good to insert big tables in pieces:"

    INSERT INTO newtable SELECT * FROM oldtable
    WHERE yourkey > something AND yourkey <= somethingelse;
    

    After all records have been inserted, you can rename the tables.

  • "During the conversion of big tables, you should increase the size of the InnoDB buffer pool to reduce disk I/O."

  • "Make sure that you do not fill up the tablespace: InnoDB tables require a lot more disk space than MyISAM tables. If an ALTER TABLE operation runs out of space, it starts a rollback, and that can take hours if it is disk-bound."

Upvotes: 4

Mchl
Mchl

Reputation: 62395

Because it needs to basically create a new table, copy all the data, create new indexes, and drop the old table. Both storage engines have very different ways of storing data on disk, so the conversion is nothing simple.

You could try just dumping the table into SQL, edit the dump so that create table statement uses InnoDB instead of MyISAM, and upload it back. I think it could be a bit faster.

Also notice, that default values for InnoDB buffer pool in your my.cnf can be really low, resulting in InnoDB not getting nearly enough memory to work effectively.

Upvotes: 3

Related Questions