mysql> show create table linuxidc\G
*************************** 1. row ***************************
Table: linuxidc
Create Table: CREATE TABLE `linuxidc` (
`actor_id` smallint(8) unsigned NOT NULL,
`first_name` varchar(45) NOT NULL,
`last_name` varchar(45) NOT NULL,
`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`vname` varchar(20) DEFAULT NULL,
PRIMARY KEY (`actor_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
添加多个字段:
[root@linuxidc ~]# pt-online-schema-change -u root -plinuxidc -h127.0.0.1 --alter='add column aname varchar(20),add column bname varchar(30)' --execute D=linuxidc,t=linuxidc
No slaves found. See --recursion-method if host linuxidc.com has slaves.
Not checking slave lag because no slaves were found and --check-slave-lag was not specified.
Operation, tries, wait:
copy_rows, 10, 0.25
create_triggers, 10, 1
drop_triggers, 10, 1
swap_tables, 10, 1
update_foreign_keys, 10, 1
Altering `linuxidc`.`linuxidc`...
Creating new table...
Created new table linuxidc._linuxidc_new OK.
Altering new table...
Altered `linuxidc`.`_linuxidc_new` OK.
2016-01-08T18:04:25 Creating triggers...
2016-01-08T18:04:25 Created triggers OK.
2016-01-08T18:04:25 Copying approximately 200 rows...
2016-01-08T18:04:25 Copied rows OK.
2016-01-08T18:04:25 Swapping tables...
2016-01-08T18:04:26 Swapped original and new tables OK.
2016-01-08T18:04:26 Dropping old table...
2016-01-08T18:04:26 Dropped old table `linuxidc`.`_linuxidc_old` OK.
2016-01-08T18:04:26 Dropping triggers...
2016-01-08T18:04:26 Dropped triggers OK.
Successfully altered `linuxidc`.`linuxidc`.
mysql> show create table linuxidc\G
*************************** 1. row ***************************
Table: linuxidc
Create Table: CREATE TABLE `linuxidc` (
`actor_id` smallint(8) unsigned NOT NULL,
`first_name` varchar(45) NOT NULL,
`last_name` varchar(45) NOT NULL,
`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`vname` varchar(20) DEFAULT NULL,
`aname` varchar(20) DEFAULT NULL,
`bname` varchar(30) DEFAULT NULL,
PRIMARY KEY (`actor_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
删除字段:
[root@linuxidc ~]# pt-online-schema-change -u root -plinuxidc -h127.0.0.1 --alter='drop column aname,drop column bname' --execute D=linuxidc,t=linuxidc
No slaves found. See --recursion-method if host linuxidc.com has slaves.
Not checking slave lag because no slaves were found and --check-slave-lag was not specified.
Operation, tries, wait:
copy_rows, 10, 0.25
create_triggers, 10, 1
drop_triggers, 10, 1
swap_tables, 10, 1
update_foreign_keys, 10, 1
Altering `linuxidc`.`linuxidc`...
Creating new table...
Created new table linuxidc._linuxidc_new OK.
Altering new table...
Altered `linuxidc`.`_linuxidc_new` OK.
2016-01-08T18:05:45 Creating triggers...
2016-01-08T18:05:45 Created triggers OK.
2016-01-08T18:05:45 Copying approximately 200 rows...
2016-01-08T18:05:45 Copied rows OK.
2016-01-08T18:05:45 Swapping tables...
2016-01-08T18:05:45 Swapped original and new tables OK.
2016-01-08T18:05:45 Dropping old table...
2016-01-08T18:05:45 Dropped old table `linuxidc`.`_linuxidc_old` OK.
2016-01-08T18:05:45 Dropping triggers...
2016-01-08T18:05:46 Dropped triggers OK.
Successfully altered `linuxidc`.`linuxidc`.
添加索引:
[root@linuxidc ~]# pt-online-schema-change -u root -plinuxidc -h127.0.0.1 --alter='add key index_first(first_name)' --execute D=linuxidc,t=linuxidc No slaves found. See --recursion-method if host linuxidc.com has slaves.
Not checking slave lag because no slaves were found and --check-slave-lag was not specified.
Operation, tries, wait:
copy_rows, 10, 0.25
create_triggers, 10, 1
drop_triggers, 10, 1
swap_tables, 10, 1
update_foreign_keys, 10, 1
Altering `linuxidc`.`linuxidc`...
Creating new table...
Created new table linuxidc._linuxidc_new OK.
Altering new table...
Altered `linuxidc`.`_linuxidc_new` OK.
2016-01-08T18:06:38 Creating triggers...
2016-01-08T18:06:38 Created triggers OK.
2016-01-08T18:06:38 Copying approximately 200 rows...
2016-01-08T18:06:38 Copied rows OK.
2016-01-08T18:06:38 Swapping tables...
2016-01-08T18:06:38 Swapped original and new tables OK.
2016-01-08T18:06:38 Dropping old table...
2016-01-08T18:06:38 Dropped old table `linuxidc`.`_linuxidc_old` OK.
2016-01-08T18:06:38 Dropping triggers...
2016-01-08T18:06:38 Dropped triggers OK.
Successfully altered `linuxidc`.`linuxidc`.