当前位置:网站首页>TiCDC迁移-TiDB到MySQL测试
TiCDC迁移-TiDB到MySQL测试
2022-08-04 08:58:00 【TiDB社区干货传送门】
作者: 18515065291 原文来源:https://tidb.net/blog/1bd64e9e
1、前言
因最近有TiDB回迁MySQL的业务需求,需要测试TiDB 到MySQL的迁移过程,本次利用dumpling导出+TiCDC进行初始数据+实时同步迁移。
2、信息
TiDB集群版本:5.2.2
来源TiDB集群:666-1
目标MySQL集群:888-1
导出工具:dumpling
导入工具:执行SQL文件
实时同步:TiCDC
MySQL主实例IP:10.5.5.5
TiDB中控机:10.4.4.4
3、部署TiCDC
集群666-1
【生成TiCDC扩容配置】:
vim add.ymlcdc_servers:- host: 10.1.1.1 port: 777 deploy_dir: /opt/tidb666/deploy/cdc-777 data_dir: /opt/tidb666/data/cdc-777 log_dir: /opt/tidb666/log/cdc-777- host: 10.1.1.2 port: 777 deploy_dir: /opt/tidb666/deploy/cdc-777 data_dir: /opt/tidb666/data/cdc-777 log_dir: /opt/tidb666/log/cdc-777- host: 10.1.1.3 port: 777 deploy_dir: /opt/tidb666/deploy/cdc-777 data_dir: /opt/tidb666/data/cdc-777 log_dir: /opt/tidb666/log/cdc-777
【执行部署】:
tiup cluster scale-out 666_TEST add.yml
【查看拓扑】:
qtidb -c 666-1
4、导出数据
cd tidb-toolkit-v5.2.2-linux-amd64/bin./dumpling -udba -pxxx -h10.x.x.x -P666 --status-addr 999 -F 64MiB -t 2 -o 666_dump -B dba_test >> 666_dump_log
【查看备份的文件】:
[tidb() bin]$ ll 666_dump/total 24-rw-rw-r-- 1 tidb tidb 146 Jul 24 11:34 metadata-rw-rw-r-- 1 tidb tidb 109 Jul 24 11:34 dba_test-schema-create.sql-rw-rw-r-- 1 tidb tidb 112 Jul 24 11:34 dba_test.test.000000000.sql-rw-rw-r-- 1 tidb tidb 66 Jul 24 11:34 dba_test.test2.000000000.sql-rw-rw-r-- 1 tidb tidb 266 Jul 24 11:34 dba_test.test2-schema.sql-rw-rw-r-- 1 tidb tidb 265 Jul 24 11:34 dba_test.test-schema.sql
【查看备份的点位】:
cat metadata Started dump at: 2022-07-24 11:34:31SHOW MASTER STATUS: Log: tidb-binlog Pos: 434800865229668357 GTID:Finished dump at: 2022-07-24 11:34:31
【TiDB666 模拟新写入数据】:
(dba:666)@[(none)]>use dba_testDatabase changed(dba:666)@[dba_test]>show tables;+------------------------------+| Tables_in_dba_test |+------------------------------+| test || test2 |+------------------------------+2 rows in set (0.00 sec)(dba:666)@[dba_test]>select * from test;+----+------+| id | name |+----+------+| 1 | aa || 33 | ccc || 44 | ddd || 55 | eee || 66 | ff |+----+------+5 rows in set (0.00 sec)(dba:666)@[dba_test]>insert into test values (77,'gg');Query OK, 1 row affected (0.01 sec)(dba:666)@[dba_test]>insert into test values (88,'re');Query OK, 1 row affected (0.00 sec)(dba:666)@[dba_test]>select * from test;+----+------+| id | name |+----+------+| 1 | aa || 33 | ccc || 44 | ddd || 55 | eee || 66 | ff || 77 | gg || 88 | re |+----+------+7 rows in set (0.00 sec)
5、MySQL导入数据
5.1、拷贝导出的备份到MySQL主实例的机器
scp -r 666_dump 10.5.5.5:/data/
5.2、执行导入
ssh 主实例机器登录mysql([email protected](none))>show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || sys || performance_schema |+--------------------+9 rows in set (0.00 sec)([email protected](none))>source /data/666_dump/dba_test-schema-create.sqlQuery OK, 0 rows affected (0.00 sec)Query OK, 1 row affected (0.00 sec)([email protected](none))>show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || sys || dba_test |+--------------------+10 rows in set (0.00 sec)([email protected](none))>use dba_testDatabase changed([email protected]_test)>source /data/666_dump/dba_test.test2-schema.sqlQuery OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)([email protected]_test)>source /data/666_dump/dba_test.test-schema.sqlQuery OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)([email protected]_test)>show tables;+------------------------------+| Tables_in_dba_test |+------------------------------+| test || test2 |+------------------------------+2 rows in set (0.00 sec)([email protected]_test)>select * from test;Empty set (0.00 sec)([email protected]_test)>select * from test2;Empty set (0.00 sec)([email protected]_test)>source /data/666_dump/dba_test.test.000000000.sqlQuery OK, 0 rows affected (0.00 sec)Query OK, 5 rows affected (0.00 sec)Records: 5 Duplicates: 0 Warnings: 0([email protected]_test)>source /data/666_dump/dba_test.test2.000000000.sqlQuery OK, 0 rows affected (0.00 sec)Query OK, 1 row affected (0.00 sec)([email protected]_test)>select * from test;+----+------+| id | name |+----+------+| 1 | aa || 33 | ccc || 44 | ddd || 55 | eee || 66 | ff |+----+------+5 rows in set (0.00 sec)([email protected]_test)>select * from test2;+----+------+| id | name |+----+------+| 2 | bb |+----+------+1 row in set (0.00 sec)
6、实时同步
6.1、查看TiCDC
ssh 10.4.4.4[root()@name-2-2 ~]# su - tidbLast login: Sun Jul 24 11:28:38 CST 2022 on pts/0[tidb()@name-2-2 ~]$ tiup ctl:v5.2.2 cdc capture list --pd=http://10.3.3.3:678Starting component `ctl`: /home/tidb/.tiup/components/ctl/v5.2.2/ctl cdc capture list --pd=http://10.3.3.3:678[ { "id": "42492be0-dd2b-49da-9562-86ba5feff288", "is-owner": false, "address": "10.1.1.1:567" }, { "id": "5543f93e-e0c8-4e91-a468-88362454b958", "is-owner": false, "address": "10.1.1.2:567" }, { "id": "6688a5c7-0779-487e-86f6-46b068743652", "is-owner": true, "address": "10.1.1.3:567" }]
6.2、创建同步任务: 【配置文件】:
[tidb()@name-2-2 666_ticdc]$ cd /data/tidb/666_ticdc[tidb()@name-2-2 666_ticdc]$ cat 666_888_ticdc_config.tomlcase-sensitive = trueenable-old-value = true[filter]rules = ['dba_test.*'][mounter]worker-num = 8
【创建同步任务】:
[tidb()@name-2-2 666_ticdc]$ tiup ctl:v5.2.2 cdc changefeed create --pd=http://10.3.3.3:678 --sink-uri="mysql://dba:[email protected]:888/?worker-count=16&max-txn-row=5000&time-zone=SYSTEM" --changefeed-id="666-888-20220724-task" --sort-engine="unified" --start-ts=434800865229668357 --config 666_888_ticdc_config.tomlStarting component `ctl`: /home/tidb/.tiup/components/ctl/v5.2.2/ctl cdc changefeed create --pd=http://10.3.3.3:678 --sink-uri=mysql://dba:[email protected]:888/?worker-count=16&max-txn-row=5000&time-zone=SYSTEM --changefeed-id=666-888-20220724-task --sort-engine=unified --start-ts=434800865229668357 --config 666_888_ticdc_config.tomlCreate changefeed successfully!ID: 666-888-20220724-taskInfo: {"sink-uri":"mysql://dba:[email protected]:888/?worker-count=16\u0026max-txn-row=5000\u0026time-zone=SYSTEM","opts":{"_changefeed_id":"cli-verify"},"create-time":"2022-07-24T12:20:45.606052447+08:00","start-ts":434800865229668357,"target-ts":0,"admin-job-type":0,"sort-engine":"unified","sort-dir":"","config":{"case-sensitive":true,"enable-old-value":true,"force-replicate":false,"check-gc-safe-point":true,"filter":{"rules":["dba_test.*"],"ignore-txn-start-ts":null},"mounter":{"worker-num":8},"sink":{"dispatchers":null,"protocol":"default"},"cyclic-replication":{"enable":false,"replica-id":0,"filter-replica-ids":null,"id-buckets":0,"sync-ddl":false},"scheduler":{"type":"table-number","polling-time":-1}},"state":"normal","history":null,"error":null,"sync-point-enabled":false,"sync-point-interval":600000000000,"creator-version":"v5.2.2"}
【查看所有任务】:
tiup ctl:v5.2.2 cdc changefeed list --pd=http://10.3.3.3:678 [tidb()@name-2-2 666_ticdc]$ tiup ctl:v5.2.2 cdc changefeed list --pd=http://10.3.3.3:678Starting component `ctl`: /home/tidb/.tiup/components/ctl/v5.2.2/ctl cdc changefeed list --pd=http://10.3.3.3:678[ { "id": "666-888-20220724-task", "summary": { "state": "normal", "tso": 434801605865111553, "checkpoint": "2022-07-24 12:21:36.983", "error": null } }]
【查看指定的任务】:
[tidb()@name-2-2 666_ticdc]$ tiup ctl:v5.2.2 cdc changefeed query -s --pd=http://10.3.3.3:678 --changefeed-id=666-888-20220724-taskStarting component `ctl`: /home/tidb/.tiup/components/ctl/v5.2.2/ctl cdc changefeed query -s --pd=http://10.3.3.3:678 --changefeed-id=666-888-20220724-task{ "state": "normal", "tso": 434801616101834753, "checkpoint": "2022-07-24 12:22:16.033", "error": null}
【查看任务详细信息】:
[tidb()@name-2-2 666_ticdc]$ tiup ctl:v5.2.2 cdc changefeed query --pd=http://10.3.3.3:678 --changefeed-id=666-888-20220724-taskStarting component `ctl`: /home/tidb/.tiup/components/ctl/v5.2.2/ctl cdc changefeed query --pd=http://10.3.3.3:678 --changefeed-id=666-888-20220724-task{ "info": { "sink-uri": "mysql://dba:[email protected]:888/?worker-count=16\u0026max-txn-row=5000\u0026time-zone=SYSTEM", "opts": { "_changefeed_id": "cli-verify" }, "create-time": "2022-07-24T12:20:45.606052447+08:00", "start-ts": 434800865229668357, "target-ts": 0, "admin-job-type": 0, "sort-engine": "unified", "sort-dir": "", "config": { "case-sensitive": true, "enable-old-value": true, "force-replicate": false, "check-gc-safe-point": true, "filter": { "rules": [ "dba_test.*" ], "ignore-txn-start-ts": null }, "mounter": { "worker-num": 8 }, "sink": { "dispatchers": null, "protocol": "default" }, "cyclic-replication": { "enable": false, "replica-id": 0, "filter-replica-ids": null, "id-buckets": 0, "sync-ddl": false }, "scheduler": { "type": "table-number", "polling-time": -1 } }, "state": "normal", "history": null, "error": null, "sync-point-enabled": false, "sync-point-interval": 600000000000, "creator-version": "v5.2.2" }, "status": { "resolved-ts": 434801631581437953, "checkpoint-ts": 434801631581437953, "admin-job-type": 0 }, "count": 0, "task-status": [ { "capture-id": "42492be0-dd2b-49da-9562-86ba5feff288", "status": { "tables": null, "operation": null, "admin-job-type": 0 } }, { "capture-id": "5543f93e-e0c8-4e91-a468-88362454b958", "status": { "tables": { "878": { "start-ts": 434800865229668357, "mark-table-id": 0 } }, "operation": {}, "admin-job-type": 0 } }, { "capture-id": "6688a5c7-0779-487e-86f6-46b068743652", "status": { "tables": { "880": { "start-ts": 434800865229668357, "mark-table-id": 0 } }, "operation": {}, "admin-job-type": 0 } } ]}
6.3、MySQL校验同步情况
【查看MySQL数据】:
([email protected]_test)>select * from test;+----+------+| id | name |+----+------+| 1 | aa || 33 | ccc || 44 | ddd || 55 | eee || 66 | ff || 77 | gg || 88 | re |+----+------+7 rows in set (0.00 sec)
【再次模拟写入】:
【TiDB666-1】:写入数据(dba:666)@[dba_test]>insert into test values (99,'we');Query OK, 1 row affected (0.00 sec)(dba:666)@[dba_test]>select * from test;+----+------+| id | name |+----+------+| 1 | aa || 33 | ccc || 44 | ddd || 55 | eee || 66 | ff || 77 | gg || 88 | re || 99 | we |+----+------+8 rows in set (0.00 sec)【MySQL888-1】:查看数据([email protected]_test)>select * from test;+----+------+| id | name |+----+------+| 1 | aa || 33 | ccc || 44 | ddd || 55 | eee || 66 | ff || 77 | gg || 88 | re || 99 | we |+----+------+8 rows in set (0.00 sec)综上:同步正常
【测试过滤是否生效】:
【TiDB666-1】:dba_test2 库写入数据(dba:666)@[dba_test]>use dba_test2Database changed(dba:666)@[dba_test2]>show tables;+-------------------------+| Tables_in_dba_test2 |+-------------------------+| tb_test |+-------------------------+1 row in set (0.00 sec)(dba:666)@[dba_test2]>select * from tb_test;+----+------+------------+| id | age | statDate |+----+------+------------+| 1 | 2 | 2021-12-22 || 2 | 2 | 2021-12-22 |+----+------+------------+2 rows in set (0.00 sec)(dba:666)@[dba_test2]>insert into tb_test values (3,1,'2022-07-24');Query OK, 1 row affected (0.00 sec)(dba:666)@[dba_test2]>select * from tb_test;+----+------+------------+| id | age | statDate |+----+------+------------+| 1 | 2 | 2021-12-22 || 2 | 2 | 2021-12-22 || 3 | 1 | 2022-07-24 |+----+------+------------+3 rows in set (0.00 sec)(dba:666)@[dba_test2]>use dba_testDatabase changed(dba:666)@[dba_test]>insert into test values (100,'ee');Query OK, 1 row affected (0.00 sec)【MySQL888-1】:查看同步([email protected]_test)>select * from test;+-----+------+| id | name |+-----+------+| 1 | aa || 33 | ccc || 44 | ddd || 55 | eee || 66 | ff || 77 | gg || 88 | re || 99 | we || 100 | ee |+-----+------+9 rows in set (0.00 sec)综上:说明库过滤ok
6.4、关闭任务
【停止任务】:
[tidb()@name-2-2 666_ticdc]$ tiup ctl:v5.2.2 cdc changefeed remove --pd=http://10.3.3.3:678 --changefeed-id 666-888-20220724-taskStarting component `ctl`: /home/tidb/.tiup/components/ctl/v5.2.2/ctl cdc changefeed remove --pd=http://10.3.3.3:678 --changefeed-id 666-888-20220724-task
【查看任务】:
[tidb()@name-2-2 666_ticdc]$ tiup ctl:v5.2.2 cdc changefeed query --pd=http://10.3.3.3:678 --changefeed-id=666-888-20220724-taskStarting component `ctl`: /home/tidb/.tiup/components/ctl/v5.2.2/ctl cdc changefeed query --pd=http://10.3.3.3:678 --changefeed-id=666-888-20220724-task[2022/07/24 12:29:30.408 +08:00] [WARN] [cli_changefeed_query.go:100] ["This changefeed has been deleted, the residual meta data will be completely deleted within 24 hours."] [changgefeed=666-888-20220724-task][2022/07/24 12:29:30.409 +08:00] [ERROR] [cli_changefeed_query.go:109] ["This changefeed does not exist"] [changefeed=666-888-20220724-task]Error: [CDC:ErrChangeFeedNotExists]changefeed not exists, key: /tidb/cdc/job/666-888-20220724-taskUsage: cdc cli changefeed query [flags]Flags: -c, --changefeed-id string Replication task (changefeed) ID -h, --help help for query -s, --simple Output simplified replication statusGlobal Flags: --ca string CA certificate path for TLS connection --cert string Certificate path for TLS connection -i, --interact Run cdc cli with readline --key string Private key path for TLS connection --log-level string log level (etc: debug|info|warn|error) (default "warn") --pd string PD address, use ',' to separate multiple PDs (default "http://127.0.0.1:2379")[CDC:ErrChangeFeedNotExists]changefeed not exists, key: /tidb/cdc/job/666-888-20220724-taskError: exit status 1Error: run `/home/tidb/.tiup/components/ctl/v5.2.2/ctl` (wd:/home/tidb/.tiup/data/TCTXh8X) failed: exit status 1
【查看任务详细】:
[tidb()@name-2-2 666_ticdc]$ tiup ctl:v5.2.2 cdc changefeed query -s --pd=http://10.3.3.3:678 --changefeed-id=666-888-20220724-taskStarting component `ctl`: /home/tidb/.tiup/components/ctl/v5.2.2/ctl cdc changefeed query -s --pd=http://10.3.3.3:678 --changefeed-id=666-888-20220724-task{ "state": "", "tso": 0, "checkpoint": "", "error": null}
边栏推荐
- 2022-08-02 Analyze RK817 output 32k clock PMIC_32KOUT_WIFI to WiFi module clock register devm_clk_hw_register
- Grafana9.0发布,Prometheus和Loki查询生成器、全新导航、热图面板等新功能!
- 智能健身动作识别:PP-TinyPose打造AI虚拟健身教练!
- Convert callback function to Flow
- .NET深入解析LINQ框架(五:IQueryable、IQueryProvider接口详解)
- 金仓数据库KingbaseES客户端编程接口指南-JDBC(7. JDBC事务处理)
- How to import data from PG to kingbaseES
- Shared_preload_libraries cause many syntaxes not supported
- 金仓数据库 KDTS 迁移工具使用指南 (6. 注意事项)
- 【论文笔记】Delving into the Estimation Shift of Batch Normalization in a Network
猜你喜欢
今年37了,被大厂抢着要...
交换机链路聚合详解【华为eNSP】
【UE虚幻引擎】UE5三步骤实现AI漫游与对话行为
DWB主题事实及ST数据应用层构建,220803,,
【电脑录制屏】如何使用bandicam录游戏 设置图文教程
inject() can only be used inside setup() or functional components.
[Computer recording screen] How to use bandicam to record the game setting graphic tutorial
学会 Arthas,让你 3 年经验掌握 5 年功力
使用单调栈解决接雨水问题——LeetCode 42 接雨水+单调栈说明
TCP的四次挥手
随机推荐
oracle sql 多表查询
布局管理器
async - await
下午14:00面试,14:08低着头出来了 ,问的实在是太...
基于cRIO-904X搭建Simulink与Labview环境
cannot import name ‘import_string‘ from ‘werkzeug‘【bug解决】
【无标题】
并查集介绍和基于并查集解决问题——LeetCode 952 按公因数计算最大组件大小
『递归』递归概念与典型实例
【虚幻引擎UE】UE5基于Gltf加载插件实现gltf格式骨骼动画在线/本地导入和切换
阿里云的数据库系统怎么升级更新的www.zgysffm.com怎么加快访问速度?
经典二分法查找的进阶题目——LeetCode33 搜索旋转排序数组
Anton Paar安东帕密度计比重计维修DMA35性能参数
Oracle怎么获取当前库或者同一台服务器上某几个库的数据总行数?
金仓数据库 KDTS 迁移工具使用指南 (5. SHELL版使用说明)
Quick tips for getting out of a single
How to write patents are more likely to pass?
怎么写专利更容易通过?
C语言strchr()函数以及strstr()函数的实现
2022年制冷与空调设备运行操作特种作业证考试题库及模拟考试