Reputation: 203
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?
Upvotes: 15
Views: 5485
Reputation: 171
Assuming an INNODB table:
Upvotes: 2
Reputation: 99687
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.
Upvotes: 6
Reputation: 39490
Don't do this live on an active system. For an active system, do this while you take the system down for regular maintenance.
Upvotes: 2