Kettle - 基于触发器的CDC
Kettle - 基于触发器的CDC
相关表
student_cdc
1 | -- ---------------------------- |
cdc_opt_log
1 | DROP TABLE IF EXISTS `cdc_opt_log`; |
student_cdc_sync
1 | DROP TABLE IF EXISTS `student_cdc_sync`; |
测试SQL
基于Insert的CDC
在数据库表 student_cdc 中插入一条数据,此时insert触发器会在cdc_opt_log表中增加一条操作记录。
使用kettle,查询cdc_opt_log表中新插入 (插入且未处理) 的学生的学号;
根据学号查询student_cdc表,将新增学生记录导出到student_cdc_sync表(新增导出时间字段);
最后更改操作日志表cdc_opt_log的处理标志字段值为已处理。
相关步骤
插入数据
1 | INSERT INTO student_cdc (姓名,性别,班级,年龄,成绩,身高,手机,插入时间,更新时间) |

步骤:操作日志表

1 | select 学号 from cdc_opt_log where 操作='I' and 处理标志='未处理' |
步骤:学生表

1 | select *, curdate() as '导入时间', '已处理' as 处理标志 from student_cdc where 学号=? |
步骤:更新学生同步表

步骤:更新操作日志表

基于Update的CDC
相关步骤
更新数据
1 | update student_cdc set 成绩=82 where 学号=4; |
步骤
1 | select 学号 from cdc_opt_log where 操作='U' and 处理标志='未处理' |
其他步骤与**基于Insert的CDC**一致。
基于Delete的CDC
相关步骤
删除数据
1 | delete from student_cdc where 学号=4; |
步骤:操作日志表

1 | select 学号 from cdc_opt_log where 操作='D' and 处理标志='未处理'; |
步骤:删除学生同步表记录

步骤:更新操作日志表

All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.