pt-online-schema-change工作机制
1) 如果存在外键,根据alter-foreign-keys-method参数值,检测外键相关的表,针对相应的设置进行处理;
2) 创建一个新的表,表结构修改后的数据表,用于从源数据表向新表中导入数据;
3) 创建触发器,在复制数据开始之后,将对源数据表继续进行数据修改的操作记录下来,以便在数据复制结束后执行这些操作,保证数据不会丢失;
4) 复制数据,从源数据表中复制数据到新表中;
5) 修改外键相关的子表,根据修改后的数据,修改外键关联的子表;
6) 更改源数据表为old表,把新表更改为源表名,并将old表删除;
7) 删除触发器
错误一:
# pt-online-schema-change –alter="add column tag_common text default null" –user=root –password=xxxxxxxx D=MYDB,t=MYTB –execute
Cannot connect to D=lsedata_13Q1,h=10.13.7.47,p=…,u=root
No slaves found. See –recursion-method if host BJL1-Y13-10-ops.gaoder.net has slaves.
Not checking slave lag because no slaves were found and –check-slave-lag was not specified.
# A software update is available:
# * Percona Toolkit 2.2.6 has a possible security issue (CVE-2014-2029) upgrade is recommended. The current version for Percona::Toolkit is 2.2.7.
The table `MYDB`.`MYTB` has triggers. This tool needs to create its own triggers, so the table cannot already have triggers.
这个错误是因为MYTB表上已经有触发器了。mysql低版本对触发器限制比较多,在5.7中的限制会少一些。就看pt-online-schema-change新版本会解决这个表上不能有触发器的问题不。
目前的解决方案,就是删除表上已经存在的触发器。
5.7的官方文档
Triggers. Previously, a table could have at most one trigger for each combination of trigger event (INSERT
, UPDATE
, DELETE
) and action time (BEFORE
,AFTER
). This limitation has been lifted and multiple triggers are permitted.