首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Mysql复制数据一致性检查2

Mysql复制数据一致性检查2

作者头像
franket
发布于 2022-04-23 18:54:29
发布于 2022-04-23 18:54:29
6620
举报
文章被收录于专栏:技术杂记技术杂记

修复数据不一致

使用 pt-table-sync 来进行数据不一致修复

pt-table-sync synchronizes data efficiently between MySQL tables. This tool changes data, so for maximum safety, you should back up your data before using it . When synchronizing a server that is a replication slave with the –replicate or –sync-to-master methods, it always makes the changes on the replication master, never the replication slave directly . This is in general the only safe way to bring a replica back in sync with its master; changes to the replica are usually the source of the problems in the first place. However, the changes it makes on the master should be no-op changes that set the data to their current values, and actually affect only the replica.

pt-table-sync 是有可能改变数据的,所以要非常慎重,三思而后行

它并非在slave上执行操作,修改不一致数据,而是在master上重新插入当前值,通过同步而影响slave,从而解决数据的不一致(指定用户需要足读写权限)

Note: pt-table-sync is mature, proven in the real world, and well tested, but if used improperly it can have adverse consequences. Always test syncing first with --dry-run and --print.

代码语言:javascript
复制
[mysql@replication-check-vm ~]$ pt-table-sync --replicate test.checksum  h=slave-vm,u=root --ask-pass  --sync-to-master --databases=abc_test_db  --tables=users  --print > /tmp/users.sql
Enter password for slave-vm:       
[mysql@replication-check-vm ~]$ 

Option

Comment

--replicate

参考指定检查表中的结果来进行修复,通常是pt-table-checksum生成的

h=xxx,u=xxx

DSN选项,h代表host,u代表用户名,使用逗号分割

--ask-pass

使用提示密码的方式连接数据库,而不是使用DSN指定,更安全

--sync-to-master

将指定的DSN当作slave,尝试与它的master同步

--databases

限定检查的DB范围,可以使用逗号分割的方式指定一个db列表

--tables

限定检查的table范围,可以使用逗号分割的方式指定一个table列表

--print

不直接执行(相对于--execute),而是输出解决不一致的SQL语句

--execute

直接执行变更,使数据一致,会导致数据改变

一般我都会使用 --print 将结果导出到一个文本中,查看修改的内容进行确认,然后使用--execute自动执行,或手动执行其中部分SQL

执行完修改后,再重复上面的操作检查一次

这个工具好在,业务在线时可以执行,不会对系统造成很大影响(会产生一定量的读IO,但不会产生有明显业务影响的锁),特别是在大表,核心表数据一致性检查时太能解渴了


原文地址

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

目录
  • 修复数据不一致
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档