Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a new column in a large mysql table

What would be the fastest way to add a new column in a large mysql table ?

Alter table add column creates a copy of the full table, and then replaces the old one with the new create table. While this process is running, the original table is readable, but all inserts and updates are stalled.

On large tables, the copy can take a long time, is there any way to reduce it ?

like image 496
Maraino Avatar asked Jun 18 '09 22:06

Maraino


2 Answers

You are stuck doing the ALTER TABLE. The best possible way to effectively deal with this, is to use a MASTER-MASTER setup.

You can modify MASTER1 first, and just use MASTER2 in production. Then you switch over and do the exact opposite.

like image 153
Evert Avatar answered Oct 14 '22 04:10

Evert


Don't do this live on an active system. For an active system, do this while you take the system down for regular maintenance.

like image 41
Paul Sonier Avatar answered Oct 14 '22 03:10

Paul Sonier