tidb-sync-diff-inspector(2)(数据校验)部署、使用

二、sync-diff-inspector部署

1.下载包(https://docs.pingcap.com/zh/tidb/v6.1/download-ecosystem-tools),解压

获取:

wget https://download.pingcap.org/tidb-community-toolkit-v6.1.0-linux-amd64.tar.gz

解压tar -zxvf xxxxxxxx

2.配置环境变量

三、sync-diff-inspector使用

1.创建配置文件

vi config.toml

# Diff Configuration.

######################### Global config #########################

# 检查数据的线程数量,上下游数据库的连接数会略大于该值

check-thread-count = 4

# 如果开启,若表存在不一致,则输出用于修复的 SQL 语句

export-fix-sql = true

# 只对比表结构而不对比数据

check-struct-only = false

######################### Datasource config #########################

[data-sources.mysql1]

    host = "127.0.0.1"

    port = 3306

    user = "root"

    password = ""

    route-rules = ["rule1"]

[data-sources.mysql2]

    host = "127.0.0.1"

    port = 3306

    user = "root"

    password = ""

    route-rules = ["rule2"]

[data-sources.tidb0]

    host = "127.0.0.1"

    port = 4000

    user = "root"

    password = ""

########################### Routes ###########################

[routes.rule1]

schema-pattern = "test"        # 匹配数据源的库名,支持通配符 "*" 和 "?"

table-pattern = "table-[1-2]"  # 匹配数据源的表名,支持通配符 "*" 和 "?"

target-schema = "test"         # 目标库名

target-table = "table-0"       # 目标表名

[routes.rule2]

schema-pattern = "test"      # 匹配数据源的库名,支持通配符 "*" 和 "?"

table-pattern = "table-3"    # 匹配数据源的表名,支持通配符 "*" 和 "?"

target-schema = "test"       # 目标库名

target-table = "table-0"     # 目标表名

######################### Task config #########################

[task]

    output-dir = "./output"

    source-instances = ["mysql1", "mysql2"]

    target-instance = "tidb0"

    # 需要比对的下游数据库的表,每个表需要包含数据库名和表名,两者由 `.` 隔开

    target-check-tables = ["test.table-0"]

# Diff Configuration.

######################### Global config #########################

# 检查数据的线程数量,上下游数据库的连接数会略大于该值

check-thread-count = 4

# 如果开启,若表存在不一致,则输出用于修复的 SQL 语句

export-fix-sql = true

# 只对比表结构而不对比数据

check-struct-only = false

######################### Datasource config #########################

[data-sources.mysql1]

    host = "127.0.0.1"

    port = 3306

    user = "root"

    password = ""

    route-rules = ["rule1"]

[data-sources.mysql2]

    host = "127.0.0.1"

    port = 3306

    user = "root"

    password = ""

    route-rules = ["rule1"]

[data-sources.tidb0]

    host = "127.0.0.1"

    port = 4000

    user = "root"

    password = ""

########################### Routes ###########################

[routes.rule1]

schema-pattern = "test"      # 匹配数据源的库名,支持通配符 "*" 和 "?"

table-pattern = "table-*"    # 匹配数据源的表名,支持通配符 "*" 和 "?"

target-schema = "test"       # 目标库名

target-table = "table-0"     # 目标表名

######################### Task config #########################

[task]

    #结果输出在哪

    output-dir = "./output"

    source-instances = ["mysql1", "mysql2"]

    target-instance = "tidb0"

    # 需要比对的下游数据库的表,每个表需要包含数据库名和表名,两者由 `.` 隔开

    target-check-tables = ["test.table-0"]

2.启动校验

# sync_diff_inspector --config=/xxx/xxx/config.toml

T2/T1数据结构(structure)对等

T2/T1数据不对等

output路径下生成4个文件

 

 

1.sync_diff.log为日志

2.查看summary.txt可以发现差别

T2表上游(8)比下游(7)多1行数据,表结构一样(structure equality),上游有6行(+6)不一样,下游有5行(-5)不一样。

3.fix-on-tidb

是个路径,进去可以看到sql

replace 碰到没有的就插入有的就update

delete

4.checkpoint

默认每10秒生成一个检查点

  • 18
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

汪灵骅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值