当前位置:网站首页>从小数据量 MySQL 迁移数据到 TiDB
从小数据量 MySQL 迁移数据到 TiDB
2022-07-03 05:55:00 【添香小铺】
本文档介绍如何使用 TiDB DM (以下简称 DM)以全量+增量的模式数据到 TiDB。本文所称“小数据量”通常指 TiB 级别以下。
一般而言,受到表结构索引数目等信息、硬件以及网络环境影响,迁移速率在 30~50GB/h 不等。使用 TiDB DM 迁移的流程如下图所示。
前提条件
第 1 步:创建数据源
首先,新建 source1.yaml
文件, 写入以下内容:
# 唯一命名,不可重复。 source-id: "mysql-01" # DM-worker 是否使用全局事务标识符 (GTID) 拉取 binlog。使用前提是上游 MySQL 已开启 GTID 模式。若上游存在主从自动切换,则必须使用 GTID 模式。 enable-gtid: true from: host: "${host}" # 例如:172.16.10.81 user: "root" password: "${password}" # 支持但不推荐使用明文密码,建议使用 dmctl encrypt 对明文密码进行加密后使用 port: 3306
其次,在终端中执行下面的命令后,使用 tiup dmctl
将数据源配置加载到 DM 集群中:
tiup dmctl --master-addr ${advertise-addr} operate-source create source1.yaml
该命令中的参数描述如下:
参数 | 描述 |
---|---|
--master-addr | dmctl 要连接的集群的任意 DM-master 节点的 {advertise-addr},例如:172.16.10.71:8261 |
operate-source create | 向 DM 集群加载数据源 |
第 2 步:创建迁移任务
新建 task1.yaml
文件, 写入以下内容:
# 任务名,多个同时运行的任务不能重名。 name: "test" # 任务模式,可设为 # full:只进行全量数据迁移 # incremental: binlog 实时同步 # all: 全量 + binlog 迁移 task-mode: "all" # 下游 TiDB 配置信息。 target-database: host: "${host}" # 例如:172.16.10.83 port: 4000 user: "root" password: "${password}" # 支持但不推荐使用明文密码,建议使用 dmctl encrypt 对明文密码进行加密后使用 # 当前数据迁移任务需要的全部上游 MySQL 实例配置。 mysql-instances: - # 上游实例或者复制组 ID。 source-id: "mysql-01" # 需要迁移的库名或表名的黑白名单的配置项名称,用于引用全局的黑白名单配置,全局配置见下面的 `block-allow-list` 的配置。 block-allow-list: "listA" # 黑白名单全局配置,各实例通过配置项名引用。 block-allow-list: listA: # 名称 do-tables: # 需要迁移的上游表的白名单。 - db-name: "test_db" # 需要迁移的表的库名。 tbl-name: "test_table" # 需要迁移的表的名称。
以上内容为执行迁移的最小任务配置。关于任务的更多配置项,可以参考 DM 任务完整配置文件介绍。
第 3 步:启动任务
在你启动数据迁移任务之前,建议使用 check-task
命令检查配置是否符合 DM 的配置要求,以避免后期报错。
tiup dmctl --master-addr ${advertise-addr} check-task task.yaml
使用 tiup dmctl
执行以下命令启动数据迁移任务。
tiup dmctl --master-addr ${advertise-addr} start-task task.yaml
该命令中的参数描述如下:
参数 | 描述 |
---|---|
--master-addr | dmctl 要连接的集群的任意 DM-master 节点的 {advertise-addr},例如: 172.16.10.71:8261 |
start-task | 参数用于启动数据迁移任务 |
如果任务启动失败,可根据返回结果的提示进行配置变更后执行 start-task task.yaml 命令重新启动任务。遇到问题请参考故障及处理方法 以及常见问题。
第 4 步:查看任务状态
如需了解 DM 集群中是否存在正在运行的迁移任务及任务状态等信息,可使用 tiup dmctl
执行 query-status
命令进行查询:
tiup dmctl --master-addr ${advertise-addr} query-status ${task-name}
关于查询结果的详细解读,请参考查询状态。
第 5 步:监控任务与查看日志(可选)
要查看迁移任务的历史状态以及更多的内部运行指标,可参考以下步骤。
如果使用 TiUP 部署 DM 集群时,正确部署了 Prometheus、Alertmanager 与 Grafana,则使用部署时填写的 IP 及端口进入 Grafana,选择 DM 的 Dashboard 查看 DM 相关监控项。
DM 在运行过程中,DM-worker, DM-master 及 dmctl 都会通过日志输出相关信息。各组件的日志目录如下:
- DM-master 日志目录:通过 DM-master 进程参数
--log-file
设置。如果使用 TiUP 部署 DM,则日志目录默认位于/dm-deploy/dm-master-8261/log/
。 - DM-worker 日志目录:通过 DM-worker 进程参数
--log-file
设置。如果使用 TiUP 部署 DM,则日志目录默认位于/dm-deploy/dm-worker-8262/log/
。
边栏推荐
- Redis cannot connect remotely.
- Multithreading and high concurrency (7) -- from reentrantlock to AQS source code (20000 words, one understanding AQS)
- Troubleshooting of 32GB Jetson Orin SOM failure to brush
- 88. 合并两个有序数组
- AtCoder Beginner Contest 258(A-D)
- Redis encountered noauth authentication required
- pytorch 搭建神经网络最简版
- The programmer shell with a monthly salary of more than 10000 becomes a grammar skill for secondary school. Do you often use it!!!
- Complete set of C language file operation functions (super detailed)
- Niuke JS separator
猜你喜欢
Skywalking8.7 source code analysis (II): Custom agent, service loading, witness component version identification, transform workflow
[teacher Zhao Yuqiang] use the catalog database of Oracle
Introduction to redis using Lua script
Simple handwritten ORM framework
Loss function in pytorch multi classification
Bernoulli distribution, binomial distribution and Poisson distribution, and the relationship between maximum likelihood (incomplete)
智牛股项目--04
@Import annotation: four ways to import configuration classes & source code analysis
Exception when introducing redistemplate: noclassdeffounderror: com/fasterxml/jackson/core/jsonprocessingexception
[explain in depth the creation and destruction of function stack frames] | detailed analysis + graphic analysis
随机推荐
Core principles and source code analysis of disruptor
项目总结--04
Code generator - single table query crud - generator
Pytorch builds the simplest version of neural network
chromedriver对应版本下载
[written examination question analysis] | | get [sizeof and strlen] [pointer and array] graphic explanation + code analysis
Apache+php+mysql environment construction is super detailed!!!
Final review (Day2)
CAD插件的安装和自动加载dll、arx
[set theory] relational closure (reflexive closure | symmetric closure | transitive closure)
NG Textarea-auto-resize
Pytorch dataloader implements minibatch (incomplete)
Apache+PHP+MySQL环境搭建超详细!!!
JDBC connection database steps
Solve the 1251 client does not support authentication protocol error of Navicat for MySQL connection MySQL 8.0.11
Solve the problem of automatic disconnection of SecureCRT timeout connection
【一起上水硕系列】Day 7 内容+Day8
[teacher Zhao Yuqiang] Alibaba cloud big data ACP certified Alibaba big data product system
Simple handwritten ORM framework
Crontab command usage