percona-toolkit系列之 pt-online-schema-change

作用是主要用来修改表结构,特点是修改过程中不会造成读写阻塞。

原理是新建一张表,并修改新表结构至满足需求。在旧表建触发器,然后将旧表的数据copy到新表中。最后删除旧表,再将新表重命名成旧表。在copy数据的时候,如果旧表的数据发生改变,会通过触发器把更改映射到新表中。

使用:Usage: pt-online-schema-change [OPTIONS] DSN ,详细查看pt-online-schema-change --help

例子:pt-online-schema-change -u root -p rongzhongpwd --alter='engine=innodb' --execute D=t15,t=t1

Altering `t15`.`t1`...
Creating new table...
Created new table t15._t1_new OK.
Altering new table...
Altered `t15`.`_t1_new` OK.
Creating triggers...
Created triggers OK.
Copying approximately 15 rows...
Copied rows OK.
Swapping tables...
Swapped original and new tables OK.
Dropping old table...
Dropped old table `t15`.`_t1_old` OK.
Dropping triggers...
Dropped triggers OK.
Successfully altered `t15`.`t1`.

注意:表中必须有主键或唯一键,另表中不能有触发器

posted @ 2012-10-16 10:48  雪刚  阅读(364)  评论(0编辑  收藏  举报