二、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秒生成一个检查点