功能
支持不锁表在线修改表结构
原理
以 test.employees 为例:
- 创建新表,
test.employees_new表结构与test.employees一致 test.employees_new执行 SQLtest.employees添加触发器 (DELETE/UPDATE/INSERT)- 批量从
test.employees拷贝数据到test.employees_new,拷贝过程中通过触发器自动更新 - 修改表名,
test.employees修改为test.employees_old,test.employees_new修改为test.employees - 删除
test.employees_old和触发器
使用
参数说明
1 | --host=xxx |
添加索引
1 | $ pt-online-schema-change --user=root --password='xx' --socket=/data/mysql-tdds/mysql.sock --alter "ADD INDEX idx_address(address)" D=test,t=employees --print --execute |
删除索引
1 | $ pt-online-schema-change --user=root --password='xx' --socket=/data/mysql-tdds/mysql.sock --alter "DROP INDEX idx_address" D=test,t=employees --print --execute |