当前位置:网站首页>从小数据量 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/
。
边栏推荐
- Strategy pattern: encapsulate changes and respond flexibly to changes in requirements
- Convolution operation in convolution neural network CNN
- [Shangshui Shuo series together] day 10
- Download the corresponding version of chromedriver
- Kubernetes cluster environment construction & Deployment dashboard
- [function explanation (Part 2)] | [function declaration and definition + function recursion] key analysis + code diagram
- Kubernetes notes (II) pod usage notes
- [untitled]
- Understand the first prediction stage of yolov1
- Method of finding prime number
猜你喜欢
Why is the website slow to open?
Exception when introducing redistemplate: noclassdeffounderror: com/fasterxml/jackson/core/jsonprocessingexception
[advanced pointer (1)] | detailed explanation of character pointer, pointer array, array pointer
[Zhao Yuqiang] deploy kubernetes cluster with binary package
Mapbox tasting value cloud animation
理解 YOLOV1 第一篇 预测阶段
Bernoulli distribution, binomial distribution and Poisson distribution, and the relationship between maximum likelihood (incomplete)
MySQL 5.7.32-winx64 installation tutorial (support installing multiple MySQL services on one host)
Multithreading and high concurrency (7) -- from reentrantlock to AQS source code (20000 words, one understanding AQS)
[teacher Zhao Yuqiang] the most detailed introduction to PostgreSQL architecture in history
随机推荐
Leetcode solution - 01 Two Sum
Kubernetes resource object introduction and common commands (V) - (configmap)
Detailed explanation of iptables (1): iptables concept
JS implements the problem of closing the current child window and refreshing the parent window
Alibaba cloud Alipay sandbox payment
[function explanation (Part 1)] | | knowledge sorting + code analysis + graphic interpretation
Capacity expansion mechanism of map
Understand one-way hash function
[minesweeping of two-dimensional array application] | [simple version] [detailed steps + code]
Personal outlook | looking forward to the future from Xiaobai's self analysis and future planning
Linux登录MySQL出现ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
How to create and configure ZABBIX
[Shangshui Shuo series together] day 10
[Zhao Yuqiang] deploy kubernetes cluster with binary package
Ext4 vs XFS -- which file system should you use
[teacher Zhao Yuqiang] index in mongodb (Part 1)
Final review (Day6)
pytorch 搭建神经网络最简版
JDBC connection database steps
Configure DTD of XML file