How do you change the schema of a large MySQL table without downtime?
Short answer
Use MySQL's online DDL (ALGORITHM=INPLACE / INSTANT) when the change supports it, or an online schema change tool like gh-ost or pt-online-schema-change for big tables. They build a new copy of the table in the background, keep it in sync, then swap it in with a very short lock. And make the change backward-compatible with the running app.
Option 1: native online DDL
ALTER TABLE orders ADD COLUMN notes VARCHAR(255) NULL, ALGORITHM=INSTANT; -- MySQL 8: metadata only
ALTER TABLE orders ADD INDEX idx_status (status), ALGORITHM=INPLACE, LOCK=NONE;
If the change can't be done that way, MySQL errors instead of silently locking the table.
Option 2: gh-ost
gh-ost --host=db --database=shop --table=orders \
--alter="MODIFY COLUMN total DECIMAL(12,2)" \
--chunk-size=1000 --max-load=Threads_running=25 --execute
Copies rows in chunks, applies ongoing changes from the binlog, throttles itself under load, then does a quick atomic table swap.
Process
- Test on a staging copy with production-like size; estimate duration.
- Check replica lag impact; run off-peak.
- Backward-compatible: add nullable columns first; don't drop/rename columns the app still uses.
What to say in the interview
"I use INSTANT or INPLACE online DDL with LOCK=NONE when supported, otherwise gh-ost or pt-online-schema-change to copy and swap the table with throttling and minimal locking. Changes follow expand/contract so the running app keeps working."