简体   繁体   English

从MyISAM到InnoDB的转换要花很多时间?

[英]Why does converting from MyISAM to InnoDB takes forever?

I wanted to convert a 700MB table from MyISAM to InnoDB with the following command: 我想使用以下命令将700MB表从MyISAM转换为InnoDB:

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. 我观察到我的内存使用率上升到60%并稳定下来。 I am suspecting that adjusting some parameter may help, but I wonder which one. 我怀疑调整某些参数可能会有所帮助,但我想知道是哪一个。

There is a discussion of issues regarding conversion to InnoDB in the MySQL docs. MySQL文档中讨论了有关转换为InnoDB 的问题

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." “在转换大表期间,应增加InnoDB缓冲池的大小以减少磁盘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." “请确保您不填满表空间:InnoDB表比MyISAM表需要更多的磁盘空间。如果ALTER TABLE操作空间不足,则会启动回滚,如果它是磁盘绑定的,则可能要花费数小时。 ”。

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. 您可以尝试将表转储到SQL中,编辑转储,以便create table语句使用InnoDB而不是MyISAM,然后将其上载回。 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. 还要注意, my.cnf InnoDB缓冲池的默认值可能确实很低,导致InnoDB无法获得足够的内存来有效工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM