写点什么

TiDB 迁移上云实践 (一) 之自建 MySQL

  • 2024-04-12
    北京
  • 本文字数:11333 字

    阅读完需:约 37 分钟

作者: 凌云 Cloud 原文来源:https://tidb.net/blog/36d7d1fc

1. 名词解释

| # | 名词 | 说明 || - | ——————- | ————————————————————————- || 1 | PD Server | Placement Driver Server 的简称,集群的管理模块。 || 2 | Pump | 用于实时记录 TiDB 产生的 Binlog,并将 Binlog 按照事务的提交时间进行排序, 再提供给 Drainer 进行消费的服务器。 || 3 | Drainer | 从各个 Pump 中收集 Binlog 进行归并,再将 Binlog 转化成 SQL 或者指定格式的数据, 最终同步到下游。 || 4 | Mydumper |  是一个 fork 项目,用于对 MySQL/TiDB 进行逻辑备份,并针对 TiDB 的特性进行了优化。 || 5 | Loader | 由 PingCAP 开发的数据导入工具,用于向 MySQL/TiDB 中导入数据。 || 6 | Sync-diff-inspector | 是一个用于校验 MySQL/TiDB 两份数据是否一致的工具。 || 7 | Tiup | TiDB 4.0 开始提供的包管理器,方便软件的安装维护,同时支持集群的部署、扩缩容和 压力测试等功能。 || 8 | Kafka | 由 Apache 软件基金会开发的一个开源流处理平台,是一种高吞吐量的分布式发布订阅消息系统。 || 9 | TSO | TimeStamp Oracle 的缩写,事务(Transaction)被分配的全局唯一时间标识。 |


注:


  • 本文的主旨是讨论验证 TiDB 迁移到云数据库产品的一般路径和步骤,不涉及特殊场景(如报错 /Bug 等)的处理。

  • 相关云数据库产品请参考官方帮助文档。

2. 迁移路径

TiDB 迁移路径



从上图中可以看到主要有 4 种迁移路径。


  • TiDB 集群通过 Pump + Drainer 同步数据到一个客户自建 MySQL 实例,然后通过 DTS 迁移到 RDS MySQLPolarDB MySQLPolarDB-XADB MySQL 等云数据库。

  • TiDB 集群通过 Pump + Drainer 同步数据到一个客户自建 Kafka 实例,然后通过 DTS 迁移到 RDS MySQL,其后还可以同步到 PolarDB-X、ADB MySQL 等云数据库。

  • TiDB 集群通过 Pump + Drainer 同步数据到 RDS MySQL,其后还可以同步到 PolarDB-X、ADB MySQL 等云数据库。

  • TiDB 集群通过 DTS 迁移全量数据到 RDS MySQL,然后通过 Pump + Drainer 实现增量数据迁移。


4 种迁移路径对比



本文详细讨论迁移路径 1。

2.1 网络

根据客户自建的 MySQL 实例所在的位置,可以分为 2 种典型场景。


  • 自建 MySQL 位于客户云上 VPC 环境中,如下图场景一示意。


  • 自建 MySQL 位于客户云下 IDC 环境中,如下图场景二示意。


场景一



场景二



场景一除了具有场景二所具有的数据迁移对 TiDB 集群没有直接的影响(DTS 全量 / 增量数据抽取都发生在自建 MySQL 实例上)的优势外,不需要网络做额外的配置,并且对网络压力更加可控,因此更加方便客户数据迁移上云。


注:


  • 具体 DTS 在两种场景下,对不同网络接入方式(VPN、专线、冗余专线、智能网关、CEN)会另文介绍,也可以参考网络和 DTS 相关文档。

2.2 迁移步骤

这里我们使用 ECS 来模拟 TiDB 集群,选择初始 TiDB 集群没有配置 Pump + Drainer 的场景。


3. 迁移

我们开始迁移的模拟,为了节约资源,我们采用所有实例部署在同一台 ECS 上的部署形式。

3.1 TiDB 集群部署


TiDB 集群


3.1.1 安装 Tiup

[root@lincloud259 ~]# cd /data[root@lincloud259 data]# mkdir -m 777 tidb_cluster
[root@lincloud259 ~]# curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh[root@lincloud259 ~]# . /root/.bash_profile[root@lincloud259 ~]# tiup cluster
复制代码

3.1.2 配置 SSH

# 配置 SSH,允许更多并发 Session[root@lincloud259 ~]# vi /etc/ssh/sshd_config[root@lincloud259 ~]# grep -i '^maxsessions' /etc/ssh/sshd_configMaxSessions 90
[root@lincloud259 ~]# systemctl restart sshd.service[root@lincloud259 ~]# sshd -T | grep -i maxsessionsmaxsessions 90
复制代码

3.1.3 部署集群

[root@lincloud259 ~]# cd /data/tidb_cluster[root@lincloud259 tidb_cluster]# vi topo.yaml# # Global variables are applied to all deployments and used as the default value of# # the deployments if a specific deployment value is missing.global: user: "tidb" ssh_port: 22 deploy_dir: "/data/tidb_cluster/tidb-deploy/jacky" data_dir: "/data/tidb_cluster/tidb-data/jacky"
# # Monitored variables are applied to all the machines.monitored: node_exporter_port: 9100 blackbox_exporter_port: 9115
server_configs: tidb: log.slow-threshold: 300 tikv: readpool.storage.use-unified-pool: false readpool.coprocessor.use-unified-pool: true pd: replication.enable-placement-rules: true tiflash: logger.level: "info"
pd_servers: - host: 10.23.199.10
tidb_servers: - host: 10.23.199.10 port: 4000 status_port: 10080
- host: 10.23.199.10 port: 4001 status_port: 10081
- host: 10.23.199.10 port: 4002 status_port: 10082
tikv_servers: - host: 10.23.199.10 port: 20160 status_port: 20180
- host: 10.23.199.10 port: 20161 status_port: 20181
- host: 10.23.199.10 port: 20162 status_port: 20182
tiflash_servers: - host: 10.23.199.10
monitoring_servers: - host: 10.23.199.10
grafana_servers: - host: 10.23.199.10
复制代码


注:


  • 因为是在同一台 ECS 上部署所有集群服务器,因此不要做 TiDB Server 的 Numa 绑定配置。

3.2 加载样例数据

配置 ECS 的安全组,允许 4000 端口的公网访问;在安装 MySQL 客户端的设备上下载样例数据库文件并加载。


[mysql@lincloud259 tidb_tmp]$ curl -L --remote-name-all https://s3.amazonaws.com/capitalbikeshare-data/2017-capitalbikeshare-tripdata.zip
[mysql@lincloud259 tidb_tmp]$ unzip \*-tripdata.zip
[mysql@lincloud259 tidb_tmp]$ mysql -h10.24.200.10 -P4000 -uroot
(root@bj4) [(none)]> CREATE DATABASE bikeshare;Query OK, 0 rows affected (0.11 sec)
(root@bj4) [(none)]> USE bikeshare;Database changed(root@bj4) [bikeshare]> CREATE TABLE trips ( trip_id bigint NOT NULL PRIMARY KEY AUTO_INCREMENT, duration integer not null, start_date datetime, end_date datetime, start_station_number integer, start_station varchar(255), end_station_number integer, end_station varchar(255), bike_number varchar(255), member_type varchar(255) );Query OK, 0 rows affected (0.15 sec)
(root@bj4) [bikeshare]> LOAD DATA LOCAL INFILE '2017Q1-capitalbikeshare-tripdata.csv' INTO TABLE trips FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES (duration, start_date, end_date, start_station_number, start_station, end_station_number, end_station, bike_number, member_type);Query OK, 646510 rows affected (25.24 sec)Records: 646510 Deleted: 0 Skipped: 0 Warnings: 0
复制代码

3.3 添加 Pump

Pump 服务器负责生成 Binlog 文件,因此在对已有 TiDB 集群添加 Pump 服务器前,不要试图开启 TiDB 服务器的 binlog 配置选项。



在 Pump Server 扩展完成后,开启 binlog。


[root@lincloud259 tidb_cluster]# tiup cluster edit-config jackyserver_configs:  tidb:    binlog.enable: true    binlog.ignore-error: true
Please check change highlight above, do you want to apply the change? [y/N]: yApply the change...Apply change successfully, please use `tiup cluster reload jacky [-N <nodes>] [-R <roles>]` to reload config.
[root@lincloud259 tidb_cluster]# su - tidb[tidb@lincloud259 ~]$ ssh-keygen -t rsaGenerating public/private rsa key pair.Enter file in which to save the key (/home/tidb/.ssh/id_rsa):Enter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /home/tidb/.ssh/id_rsa.Your public key has been saved in /home/tidb/.ssh/id_rsa.pub.The key fingerprint is:SHA256:x/piOeorfeNWt8gEHUDWGR/mKg/+Z5/B9mO5t43xyg4 tidb@iZ2zefd13t0f76cgvidpzlZThe key's randomart image is:+---[RSA 2048]----+| .+o.oo || . ++ . || . .o || .... || S.+ || . *o .. || . o=.oE.= .|| . . Ooo ++ @o|| o+B.+oo oO+O|+----[SHA256]-----+[tidb@lincloud259 ~]$ cd .ssh[tidb@lincloud259 .ssh]$ cat id_rsa.pub >> authorized_keys[tidb@lincloud259 .ssh]$ ssh 10.23.199.10[tidb@lincloud259 .ssh]$ ssh 10.26.33.96The authenticity of host '10.26.33.96 (10.26.33.96)' can't be established.ECDSA key fingerprint is SHA256:CrPbE+hWNud80v12LVq1t9KAWSx09fC7xw0+CTJEi9Y.ECDSA key fingerprint is MD5:ae:30:87:d0:35:c0:9e:20:f2:77:2c:0c:55:f7:d9:11.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added '10.26.33.96' (ECDSA) to the list of known hosts.
Welcome to Alibaba Cloud Elastic Compute Service !
[tidb@lincloud259 ~]$ exit
[tidb@lincloud259 .ssh]$ exit
[root@lincloud259 tidb_cluster]# tiup cluster reload jacky
root@lincloud259 tidb_cluster]# tiup cluster display jackyStarting component `cluster`: /root/.tiup/components/cluster/v1.0.6/tiup-cluster display jackyTiDB Cluster: jackyTiDB Version: v4.0.1ID Role Host Ports OS/Arch Status Data Dir Deploy Dir-- ---- ---- ----- ------- ------ -------- ----------10.23.199.10:3000 grafana 10.23.199.10 3000 linux/x86_64 Up - /data/tidb_cluster/tidb-deploy/jacky/grafana-300010.23.199.10:2379 pd 10.23.199.10 2379/2380 linux/x86_64 Up|L|UI /data/tidb_cluster/tidb-data/jacky/pd-2379 /data/tidb_cluster/tidb-deploy/jacky/pd-237910.23.199.10:9090 prometheus 10.23.199.10 9090 linux/x86_64 Up /data/tidb_cluster/tidb-data/jacky/prometheus-9090 /data/tidb_cluster/tidb-deploy/jacky/prometheus-909010.23.199.10:8250 pump 10.23.199.10 8250 linux/x86_64 Up /data/tidb_cluster/tidb-data/jacky/pump-8250 /data/tidb_cluster/tidb-deploy/jacky/pump-825010.23.199.10:8251 pump 10.23.199.10 8251 linux/x86_64 Up /data/tidb_cluster/tidb-data/jacky/pump-8251 /data/tidb_cluster/tidb-deploy/jacky/pump-825110.23.199.10:8252 pump 10.23.199.10 8252 linux/x86_64 Up /data/tidb_cluster/tidb-data/jacky/pump-8252 /data/tidb_cluster/tidb-deploy/jacky/pump-825210.23.199.10:4000 tidb 10.23.199.10 4000/10080 linux/x86_64 Up - /data/tidb_cluster/tidb-deploy/jacky/tidb-400010.23.199.10:4001 tidb 10.23.199.10 4001/10081 linux/x86_64 Up - /data/tidb_cluster/tidb-deploy/jacky/tidb-400110.23.199.10:4002 tidb 10.23.199.10 4002/10082 linux/x86_64 Up - /data/tidb_cluster/tidb-deploy/jacky/tidb-400210.23.199.10:9000 tiflash 10.23.199.10 9000/8123/3930/20170/20292/8234 linux/x86_64 Up /data/tidb_cluster/tidb-data/jacky/tiflash-9000 /data/tidb_cluster/tidb-deploy/jacky/tiflash-900010.23.199.10:20160 tikv 10.23.199.10 20160/20180 linux/x86_64 Up /data/tidb_cluster/tidb-data/jacky/tikv-20160 /data/tidb_cluster/tidb-deploy/jacky/tikv-2016010.23.199.10:20161 tikv 10.23.199.10 20161/20181 linux/x86_64 Up /data/tidb_cluster/tidb-data/jacky/tikv-20161 /data/tidb_cluster/tidb-deploy/jacky/tikv-2016110.23.199.10:20162 tikv 10.23.199.10 20162/20182 linux/x86_64 Up /data/tidb_cluster/tidb-data/jacky/tikv-20162 /data/tidb_cluster/tidb-deploy/jacky/tikv-20162
复制代码

3.4 全量备份

3.4.1 安装备份工具

[root@lincloud259 local]# mkdir -m 777 /data/soft/tidb[root@lincloud259 local]# cd /data/soft/tidb[root@lincloud259 tidb]# wget -c 'https://download.pingcap.org/tidb-enterprise-tools-nightly-linux-amd64.tar.gz' -O tidb-enterprise-tools-nightly-linux-amd64.tar.gz[root@lincloud259 tidb]# cp -rp tidb-enterprise-tools-nightly-linux-amd64.tar.gz /usr/local/[root@lincloud259 tidb]# cd /usr/local/[root@lincloud259 local]# tar zxpf tidb-enterprise-tools-nightly-linux-amd64.tar.gz
[root@lincloud259 local]# rm -f tidb-enterprise-tools-nightly-linux-amd64.tar.gz[root@lincloud259 local]# ln -s /usr/local/tidb-enterprise-tools-nightly-linux-amd64/ /usr/local/tidb_tools[root@lincloud259 local]# lsaegis bin etc games include lib lib64 libexec sbin share src tidb-enterprise-tools-nightly-linux-amd64 tidb_tools[root@lincloud259 bin]# vi /etc/profile# Add for /usr/local utilitiesPATH=$PATH:/usr/local/tidb_tools/binexport PATH
[root@lincloud259 bin]# . /etc/profile[root@lincloud259 bin]# which mydumper/usr/local/tidb_tools/bin/mydumper
复制代码

3.4.2 备份 TiDB 集群

[root@lincloud259 bin]# cd /data/tidb_cluster/[root@lincloud259 tidb_cluster]# mkdir -p tidb_backup/jacky[root@lincloud259 tidb_cluster]# cd tidb_backup/jacky/[root@lincloud259 jacky]# mkdir `date '+%d-%m-%Y_%H_%M_%S'`[root@lincloud259 ]# mydumper -h 127.0.0.1 -P 4000 -u root -t 32 -F 256 -B bikeshare --skip-tz-utc -o ./[root@lincloud259 ]# lsbikeshare-schema-create.sql  bikeshare.trips-schema.sql  bikeshare.trips.sql  metadata
[root@lincloud259 22-03-2024_14_46_23]# cat metadataStarted dump at: 2024-03-22 14:47:02SHOW MASTER STATUS: Log: tidb-binlog Pos: 417545171224756227 GTID:
Finished dump at: 2024-03-22 14:47:05
复制代码

3.4.3 生成 Binlog

[mysql@lincloud259 tidb_tmp]$ ls2024-lincloud259-tripdata.zip  2024Q1-capitalbikeshare-tripdata.csv  2024Q2-capitalbikeshare-tripdata.csv  2017Q3-capitalbikeshare-tripdata.csv  2017Q4-capitalbikeshare-tripdata.csv[mysql@lincloud259 tidb_tmp]$ mysql -h10.24.200.10 -P4000 -uroot(root@bj4) [(none)]> use bikeshare(root@bj4) [bikeshare]> load data local infile '2024Q2-capitalbikeshare-tripdata.csv' into table trips FIELDS TERMINATED BY ',' ENCLOSED BY '"'   LINES TERMINATED BY '\r\n'   IGNORE 1 LINES (duration, start_date, end_date, start_station_number, start_station, end_station_number, end_station, bike_number, member_type);Query OK, 1104418 rows affected (44.30 sec)Records: 1104418  Deleted: 0  Skipped: 0  Warnings: 0
复制代码

3.5 全量数据导入

因为在添加 Pump 之前,TiDB 集群已经存在并且包含数据,因此需要将全量数据导入到自建 MySQL 实例中。

3.5.1 创建 ECS 自建 MySQL 实例

当前 TiDB 全面兼容 MySQL 5.7 语法,因此自建 MySQL 实例选择 5.7 版本。


[root@lincloud259 22-03-2024_14_46_23]# cd /data/soft[root@lincloud259 soft]# mkdir mysql && cd mysql[root@lincloud259 mysql]# lsmysql-5.7.24-linux-glibc2.12-x86_64.tar.gz[root@lincloud259 mysql]# cp -rp mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz /usr/local/c[root@lincloud259 mysql]# cd /usr/local[root@lincloud259 local]# tar zxpf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz[root@lincloud259 local]# ln -s /usr/local/mysql-5.7.24-linux-glibc2.12-x86_64/ /usr/local/mysql[root@lincloud259 local]# vi /etc/profile# Add for /usr/local utilitiesPATH=$PATH:/usr/local/tidb_tools/bin:/usr/local/mysql/binexport PATH[root@lincloud259 local]# . /etc/profile[root@lincloud259 local]# which mysql/usr/local/mysql/bin/mysql
[root@lincloud259 local]# groupadd -g 500 mysql[root@lincloud259 local]# useradd -u 500 -g 500 -G disk -d /home/mysql -s /bin/bash -m mysql[root@lincloud259 local]# passwd mysql
[root@lincloud259 local]# cd /data[root@lincloud259 data]# mkdir -p mysql_data/jacky[root@lincloud259 data]# chown -R mysql:mysql mysql_data/
[root@lincloud259 data]# su - mysql[mysql@lincloud259 ~]$ cd /data/mysql_data/[mysql@lincloud259 mysql_data]$ vi my.cnf
# The MySQL server[mysqld]# Basic parametersuser = mysqlport = 3701character_set_server = utf8mb4skip-character-set-client-handshake = 1basedir = /usr/local/mysqldatadir = /data/mysql_data/jackypid-file = /data/mysql_data/jacky/mysql.pidsocket = /data/mysql_data/jacky/mysql.socklower_case_table_names = 1
# Logginglog_error = error.loglog_queries_not_using_indexes = 0long_query_time = 1slow_query_log = 1slow_query_log_file = mysql-slow.log
# Binary Logginglog_bin = binlogbinlog_format = rowbinlog_row_image = FULLexpire_logs_days = 0sync_binlog = 1
# Replicationserver_id = 1819034970master-info-repository = filerelay-log-info_repository = filegtid-mode = onenforce-gtid-consistency = true
# InnoDBinnodb_data_file_path=ibdata1:200M:autoextendinnodb_buffer_pool_size = 1Ginnodb_file_per_table = ONinnodb_flush_log_at_trx_commit = 1innodb_flush_method = O_DIRECTinnodb_log_files_in_group=2innodb_log_file_size=1048576000innodb_io_capacity = 1000innodb_io_capacity_max = 2000innodb_large_prefix = ONinnodb_undo_directory=./
# Caches & Limitsmax_connections = 500max_allowed_packet = 1048576000
[root@lincloud259 ~]# mysqld --defaults-file=/data/mysql_data/my.cnf --initialize
[root@lincloud259 ~]# cp -rp /data/mysql_data/my.cnf /data/mysql_data/jacky/my.cnf
[root@lincloud259 ~]# nohup mysqld_safe --defaults-file=/data/mysql_data/jacky/my.cnf &[root@lincloud259 ~]# netstat -nlt | grep 3701tcp6 0 0 :::3701 :::* LISTEN
[root@lincloud259 ~]# su - mysql
[mysql@lincloud259 ~]$ cd /data/mysql_data/jacky/
[mysql@lincloud259 jacky]$ grep -i root ./error.log2024-03-22T08:38:07.961728Z 1 [Note] A temporary password is generated for root@localhost: ZTy-48D,/r0k
[mysql@lincloud259 jacky]$ mysql -hlocalhost -uroot -p'ZTy-48D,/r0k' -S ./mysql.sock
mysql> set password=password('xxx');Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> grant all privileges on *.* to 'root'@'%' identified by 'xxx' with grant option;Query OK, 0 rows affected, 1 warning (0.00 sec)
## ECS 控制台修改安全组,允许公网 3701 访问,然后验证下远程可以访问
[mysql@lincloud259 tidb_tmp]$ mysql -h10.24.200.10 -uroot -pxxx -P3701(root@bj4) [(none)]> quit
复制代码

3.5.2 导入备份

[root@lincloud259 22-03-2024_14_46_23]# loader -L info -P 3701 -checkpoint-schema="tidb_loader" -d ./ -h 10.24.200.10 -t 32 -u root -p 'xxx'2024/03/22 21:20:38 printer.go:52: [info] Welcome to loader2024/03/22 21:20:38 printer.go:53: [info] Release Version: v1.0.0-79-gf505ab32024/03/22 21:20:38 printer.go:54: [info] Git Commit Hash: f505ab3ce55cd9cbb29e2346317164055a1b1c152024/03/22 21:20:38 printer.go:55: [info] Git Branch: master2024/03/22 21:20:38 printer.go:56: [info] UTC Build Time: 2024-03-23 02:40:182024/03/22 21:20:38 printer.go:57: [info] Go Version: go version go1.13 linux/amd642024/03/22 21:20:38 main.go:51: [info] config: {"log-level":"info","log-file":"","status-addr":":8272","pool-size":32,"dir":"./","db":{"host":"10.24.200.10","user":"root","port":3701,"sql-mode":"@DownstreamDefault","max-allowed-packet":67108864},"checkpoint-schema":"tidb_loader","config-file":"","route-rules":null,"do-table":null,"do-db":null,"ignore-table":null,"ignore-db":null,"rm-checkpoint":false}2024/03/22 21:20:38 loader.go:532: [info] [loader] prepare takes 0.000142 seconds2024/03/22 21:20:38 checkpoint.go:207: [info] calc checkpoint finished. finished tables (map[])2024/03/22 21:20:38 loader.go:715: [info] [loader][run db schema].//bikeshare-schema-create.sql[start]2024/03/22 21:20:38 loader.go:720: [info] [loader][run db schema].//bikeshare-schema-create.sql[finished]2024/03/22 21:20:38 loader.go:736: [info] [loader][run table schema].//bikeshare.trips-schema.sql[start]2024/03/22 21:20:38 loader.go:741: [info] [loader][run table schema].//bikeshare.trips-schema.sql[finished]2024/03/22 21:20:38 loader.go:773: [info] [loader] create tables takes 0.037831 seconds2024/03/22 21:20:38 loader.go:788: [info] [loader] all data files have been dispatched, waiting for them finished2024/03/22 21:20:38 loader.go:158: [info] [loader][restore table data sql].//bikeshare.trips.sql[start]2024/03/22 21:20:38 loader.go:216: [info] data file bikeshare.trips.sql scanned finished.2024/03/22 21:20:43 status.go:32: [info] [loader] finished_bytes = 32997729, total_bytes = GetAllRestoringFiles91120404, progress = 36.21 %2024/03/22 21:20:48 status.go:32: [info] [loader] finished_bytes = 68995049, total_bytes = GetAllRestoringFiles91120404, progress = 75.72 %2024/03/22 21:20:51 loader.go:165: [info] [loader][restore table data sql].//bikeshare.trips.sql[finished]2024/03/22 21:20:51 loader.go:791: [info] [loader] all data files has been finished, takes 13.170611 seconds2024/03/22 21:20:51 status.go:32: [info] [loader] finished_bytes = 91120404, total_bytes = GetAllRestoringFiles91120404, progress = 100.00 %2024/03/22 21:20:51 main.go:88: [info] loader stopped and exits
[root@iZ2ze5ffbqqbeatcv1j01yZ 22-03-2024_14_46_23]# mysql -h10.24.200.10 -P3701 -uroot -p'xxx' bikesharemysql> show tables;+---------------------+| Tables_in_bikeshare |+---------------------+| trips |+---------------------+1 row in set (0.00 sec)
mysql> select count(*) from trips;+----------+| count(*) |+----------+| 646510 |+----------+1 row in set (0.15 sec)
复制代码

3.6 添加 Drainer

导入全量备份后,给集群添加 Drainer 服务器同步增量数据到自建 MySQL 实例。


| # | 服务 | 数量 | Host | 端口 | Data Dir | Deploy Dir | Commit_TS || - | ——- | – | ———— | —- | ———————————————————- | ———————————————————— | —————————– || 1 | Drainer | 1 | 10.23.199.10 | 8249 | /data/tidb_cluster/tidb-data/jacky/drainer-8249 | /data/tidb_cluster/tidb-deploy/jacky/drainer-8249 | 全量备份 metadata 文件中 Pos 的值 |

3.7 验证数据

在 TiDB 上加载 2024Q3 的数据文件,同时在自建 MySQL 实例上验证数据同步效果。

3.7.1 TiDB 加载 Q3 数据

[mysql@lincloud259 tidb_tmp]$ mysql -h10.24.200.10 -uroot -P4000
(root@bj4) [(none)]> use bikeshareReading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -A
Database changed(root@bj4) [bikeshare]> select count(*) from trips;+----------+| count(*) |+----------+| 1750928 |+----------+1 row in set (0.40 sec)
(root@bj4) [bikeshare]> load data local infile '2024Q3-capitalbikeshare-tripdata.csv' into table trips FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES (duration, start_date, end_date, start_station_number, start_station, end_station_number, end_station, bike_number, member_type);Query OK, 1191585 rows affected (54.81 sec)Records: 1191585 Deleted: 0 Skipped: 0 Warnings: 0
(root@bj4) [bikeshare]> select count(*) from trips;+----------+| count(*) |+----------+| 2942513 |+----------+1 row in set (0.64 sec)
复制代码

3.7.2 自建 MySQL 验证

[root@lincloud259 tidb_cluster]# mysql -h10.24.200.10 -P3701 -uroot -p'xxx' bikeshare
mysql> select count(*) from trips;+----------+| count(*) |+----------+| 2942513 |+----------+1 row in set (0.71 sec)
mysql>
复制代码


至此数据验证完成。


发布于: 刚刚阅读数: 2
用户头像

TiDB 社区官网:https://tidb.net/ 2021-12-15 加入

TiDB 社区干货传送门是由 TiDB 社区中布道师组委会自发组织的 TiDB 社区优质内容对外宣布的栏目,旨在加深 TiDBer 之间的交流和学习。一起构建有爱、互助、共创共建的 TiDB 社区 https://tidb.net/

评论

发布
暂无评论
TiDB 迁移上云实践(一)之自建MySQL_迁移_TiDB 社区干货传送门_InfoQ写作社区