问题遇到的现象和发生背景
使用pt-archiver数据归档,--bulk-delete 批量删除操作失败
问题相关代码,请勿粘贴截图
/usr/local/bin/pt-archiver --source h=47.96.83.112,u=dxy-tech,p=123456,P=3306,D=kitty,t=t_order --dest h=47.96.83.112,P=3306,u=dxy-tech,p=123456,D=kitty,t=t_order_2021 --progress 5000 --where "create_time <'2022-01-01 00:00:00'" --statistics --charset=UTF8 --limit=10000 --txn-size 1000 --bulk-delete --bulk-insert --no-version-check --analyze=ds --purge
TIME ELAPSED COUNT
2022-07-26T13:12:01 0 0
DBD::mysql::st execute failed: Cannot delete or update a parent row: a foreign key constraint fails (kitty
.t_order_store_snapshot
, CONSTRAINT t_order_store_snapshot___fk_order_id
FOREIGN KEY (order_id
) REFERENCES t_order
(id
) ON DELETE RESTRICT ON UPDATE RESTRICT) [for Statement "DELETE FROM kitty
.t_order
WHERE (((id
>= ?))) AND (((id
<= ?))) AND (create_time <'2022-01-01 00:00:00') LIMIT 10000" with ParamValues: 0='1386858111960182785', 1='1479265036085186562'] at /usr/local/bin/pt-archiver line 6900.
运行结果及报错内容
DBD::mysql::st execute failed: Cannot delete or update a parent row: a foreign key constraint fails (kitty
.t_order_store_snapshot
, CONSTRAINT t_order_store_snapshot___fk_order_id
FOREIGN KEY (order_id
) REFERENCES t_order
(id
) ON DELETE RESTRICT ON UPDATE RESTRICT) [for Statement "DELETE FROM kitty
.t_order
WHERE (((id
>= ?))) AND (((id
<= ?))) AND (create_time <'2022-01-01 00:00:00') LIMIT 10000" with ParamValues: 0='1386858111960182785', 1='1479265036085186562'] at /usr/local/bin/pt-archiver line 6900.
我的解答思路和尝试过的方法
起初设想通过设置FOREIGN_KEY_CHECKS变量来避免这种情况,均无效
SET FOREIGN_KEY_CHECKS = 0;
删除完成后设置
SET FOREIGN_KEY_CHECKS = 1;
我想要达到的结果
这个不删除外键约束情况下怎么处理?