Mysql changing table engine MyISAM to InnoDB

你说的曾经没有我的故事 提交于 2019-11-27 17:54:14

问题


On my site I have a visitor's table with 10 million rows.
Every request to the site inserts row to the table, in case the table is locked (usually in optimize query) visitors can't get into the site
The table engine is MyISAM and I want to change it to InnoDB
I have few questions:

  • How can I change the table engine without stoping my site from working
  • There is a way to optimize InnoDB table without locking it

回答1:


The easiest way is

ALTER TABLE table_name ENGINE = InnoDB;

If you use InnoDB engine you should not worry about locking tables, because this engine locks data by rows.




回答2:


oleksii.svarychevskyi is right, InnoDB uses row level locks, but if you do

ALTER TABLE table_name ENGINE = InnoDB;
to change table_name from MyIsam to InnoDB, there will be a metadata locking (at table level) because the original table engine was MyIsam.
If you try to do an UPDATE over table_name, this UPDATE will be enqueued until the ALTER TABLE ends (if you do a SHOW FULL PROCESSLIST you will see a "Waiting for table metadata lock" message associated to the UPDATE).

来源:https://stackoverflow.com/questions/21527588/mysql-changing-table-engine-myisam-to-innodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!