Create an index on a huge MySQL production table without table locking

前端 未结 4 1540
别跟我提以往
别跟我提以往 2020-11-29 16:36

I need to create an index on a ~5M rows MySQL table. It is a production table, and I fear a complete block of everything if I run a CREATE INDEX statement...

Is the

4条回答
  •  醉话见心
    2020-11-29 17:09

    As this blog post outlines, the InnoDB ALTER TABLE mechanism has been completely redesigned for MySQL 5.6.

    (For an exclusive overview of this topic, the MySQL documentation can provide an afternoon's worth of reading.)

    To add an index to a table without a lock resulting on UPDATE/ INSERT, the following statement format can be used:

    ALTER TABLE my_table ADD INDEX my_table__idx (my_column), ALGORITHM=INPLACE, LOCK=NONE;
    

提交回复
热议问题