ALTER TABLE without locking the table?

后端 未结 19 2049
梦毁少年i
梦毁少年i 2020-11-30 17:41

When doing an ALTER TABLE statement in MySQL, the whole table is read-locked (allowing concurrent reads, but prohibiting concurrent writes) for the duration of the statement

19条回答
  •  再見小時候
    2020-11-30 18:10

    Temporary solution...

    Other solution could be, add a another table with primary key of the original table, along with your new column.

    Populate your primary key onto the new table and populate values for new column in your new table, and modify your query to join this table for select operations and you also need to insert, update separately for this column value.

    When you able to get downtime, you can alter the original table, modify your DML queries and drop your new table created earlier

    Else, you may go for clustering method, replication, pt-online-schema tool from percona

提交回复
热议问题