使用pt-online-schema-change不锁表修改表结构

1,pt-osc步骤

使用pt-online-schema-change不锁表修改表结构_第1张图片
image.png

修改表结构如添加索引、修改列,需要锁表,期间不能写入,使用pt-osc避免长时间锁表操作。在rename阶段是,也是会短暂锁表的

2,使用pt-osc添加唯一索引

1)扫描重复的client_id
select client_id, count(1) count from my_order_1.order_0 group by client_id having count>1;
2)将重复client_id修改
update my_order_1.order_0 b,(select client_id from my_order_1.order_0 where client_id = '1234567891234567') a set b.client_id = concat(b.client_id,b.id) where b.client_id = a.client_id;
3)使用pt-online-schema-change 修改表结构、增加唯一索引。
4)使用information_schema 构造sql
select concat('select client_id, count(1) count from ',table_schema,'.',table_name,' group by clinet_id having count>1;') from information_schema.tables where table_schema like '%order%' and table_name like '%_%'

你可能感兴趣的:(使用pt-online-schema-change不锁表修改表结构)