Question

Does anyone know if it is possible to add multiple columns at one time using Percona's pt-online-schema-change for MySQL? I have tried literally every variant I can think of in order to add multiple columns at one time. It seems like something you should be able to do, but I cannot find any evidence online that you can, nor can I get the syntax to work out. A few of the statements I've attempted are below, to give you an idea what I've tried (username and password edited out, for obvious reasons)

Statement 1:

    pt-online-schema-change --print --progress time,5 --max-load Threads_running=1000 
--critical-load Threads_running=10000 --chunk-time 5 --set-vars "innodb_lock_wait_timeout=600" 
--nocheck-plan --execute -h webdb -u xxxx --p xxxx --alter "ADD first_seen datetime NOT NULL 
DEFAULT 0, last_seen datetime NOT NULL DEFAULT 0 AFTER days_running"  D=mydata,t=mytable

Statement 2:

    pt-online-schema-change --print --progress time,5 --max-load Threads_running=1000 
--critical-load Threads_running=10000 --chunk-time 5 --set-vars "innodb_lock_wait_timeout=600" 
--nocheck-plan --execute -h webdb -u xxxx --p xxxx --alter "ADD first_seen datetime NOT NULL 
DEFAULT 0, ADD last_seen datetime NOT NULL DEFAULT 0 AFTER days_running"  D=mydata,t=mytable

Statement 3:

 pt-online-schema-change --print --progress time,5 --max-load Threads_running=1000 
--critical-load Threads_running=10000 --chunk-time 5 --set-vars "innodb_lock_wait_timeout=600" 
--nocheck-plan --execute -h webdb -u xxxx --p xxxx --alter "ADD first_seen datetime NOT NULL 
DEFAULT 0 AFTER days_running, ADD last_seen datetime NOT NULL DEFAULT 0 AFTER days_running"  
D=mydata,t=mytable

And so forth. Basically I've tried every variant I can think of for ADD first_seen datetime NOT NULL DEFAULT 0, ADD last_seen datetime NOT NULL DEFAULT 0 AFTER days_running" (moving/removing the after, moving/removing the ADD, moving/removing the comma, etc)

Was it helpful?

Solution

According to the manual this is possible, just separate the statements with commas. Quoting the --alter section of the manual:

--alter

type: string

The schema modification, without the ALTER TABLE keywords. You can perform 
multiple modifications to the table by specifying them with commas. Please 
refer to the MySQL manual for the syntax of ALTER TABLE.

In your case this --alter should work (assuming the rest of your statement is correct):

--alter "ADD first_seen datetime NOT NULL DEFAULT 0, ADD last_seen datetime NOT NULL DEFAULT 0 AFTER days_running"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top