28. pt-table-sync
28.1 pt-table-sync 作用

使用对两个库不一致的数据进行同步,他能够自动发现两个实例间不一致的数据,然后进行sync操作,pt-table-sync无法同步表结构,和索引等对象,只能同步数据。

可能大家多数使用该工具来解决主从数据不一致的问题,其实他的功能不止于此,也可以用来对两个不在一个主从拓扑实例,进行数据sync。

NOTE1:如果是sync主从数据,只有当需要sync的表都有唯一键(主键或唯一索引),才能使用--sync-to-master and/or --replicate。(没有唯一键,则只能在desitination上直接修改,而指定--sync-to-master and/or –replicate时只能在主库上修改),如果sync主从时没有指定--replicate或者--sync-to-master则所有修改都在从库上执行(不论表上是否有唯一键)
28.2 常用参数

常用参数请参考:pt-table-sync 中文使用说明
http://blog.csdn.net/shaochenshuo/article/details/53285439
28.3 使用示例
28.3.1  sync两个独立数据库(非主从)

1)以75为source,76为desitination,同步所有的库和表

pt-table-sync --charset=utf8--ignore-databases=mysql,sys,percona dsn=u=root,p=root,h=172.172.178.75,P=3306 dsn=u=root,p=root,h=172.172.178.76,P= --execute --print

2) 同步指定库或者指定表

只对指定的库进行sync

pt-table-sync --charset=utf8--ignore-databases=mysql,sys,percona --databases=test1 --no-check-slave dsn=u=root,p=root,h=172.172.178.75,P=3306 dsn=u=root,p=root,h=172.172.178.76,P= --execute --print

只对指定的表进行sync(也可以--tables=test5.test_nu)

pt-table-sync --charset=utf8--ignore-databases=mysql,sys,percona --databases=test5 --tables=test_nu --no-check-slave dsn=u=root,p=root,h=172.172.178.75,P=3306 dsn=u=root,p=root,h=172.172.178.76,P= --execute --print

1)       忽略某些库或者忽略某些表

忽略库

--ignore-databases=指定要忽略的库

忽略表

pt-table-sync --charset=utf8--ignore-databases=mysql,sys,percona --ignore-tables=test5.test_nu --no-check-slave dsn=u=root,p=root,h=172.172.178.75,P=3306 dsn=u=root,p=root,h=172.172.178.76,P= --execute --print

28.3.2  sync主从数据

1)没有唯一键(主键或唯一索引)

pt-table-sync --charset=utf8--ignore-databases=mysql,sys,percona --no-check-slave dsn=u=root,p=root,h=172.172.178.75,P=3306 dsn=u=root,p=root,h=172.172.178.76,P= --execute --print

##只比对76同75的数据,对差异数据进行sync

可以指定多个从库

pt-table-sync --charset=utf8--ignore-databases=mysql,sys,percona --no-check-slave dsn=u=root,p=root,h=172.172.178.75,P=3306 dsn=u=root,p=root,h=172.172.178.76,P=3306 dsn=u=root,p=root,h=172.172.178.77,P= --execute –print

##比对76同75;77同75的数据,对差异进行sync

NOTE1:在执行sync之前,我们可以指定—print(不要指定--execute)来查看pt-table-sync会进行哪些修改

NOTE2:执行sync操作时,指定忽略mysql等系统数据库(information_schema,performance_schema会自动被忽略)

NOTE3:指定--no-check-slave不检查desitination是否为从库,否则报如下错误:

Can't make changes onA=utf8,P=3306,h=172.172.178.76,p=... because it's a slave. See thedocumentation section 'REPLICATION SAFETY'

NOTE4:此种情况下修改都在从库上进行(不论表是否有唯一键)

2) 有唯一键(有唯一键时,可以使用--sync-to-master and/or –replicate进行主从sync)

pt-table-sync --execute --sync-to-master--charset=utf8 --ignore-databases=mysql,sys,percona --no-check-slave dsn=u=root,p=root,h=172.172.178.76,P= --print

NOTE1:在执行sync之前,我们可以指定--print来查看pt-table-sync会进行哪些修改

NOTE2:执行sync操作时,指定忽略mysql等系统数据库(information_schema,performance_schema会自动被忽略)

NOTE3:如果表上没有唯一索引,则无法在主库执行replace操作,会报如下错此种情况不能指定--replicate或者--sync-to-master

Can'tmake changes on the master because no unique index exists at/usr/bin/pt-table-sync line 10663.  whiledoing test1.test_concat on 172.172.178.76

NOTE4:指定了--replicate(指定dsn为主)或者--sync-to-master(指定dsn为从)只能为命令行指定一个dsn

相关链接:

pt-table-sync 中文使用说明
http://blog.csdn.net/shaochenshuo/article/details/53285439

pt-table-checksum 中文使用说明
http://blog.csdn.net/shaochenshuo/article/details/53098224

pt-table-checksum 使用方法
http://blog.csdn.net/shaochenshuo/article/details/56009092
---------------------

转自
作者:database_shaofei
来源:CSDN
原文:https://blog.csdn.net/shaochenshuo/article/details/56009234
版权声明:本文为博主原创文章,转载请附上博文链接!

锁表参数

--lock

type: int

Lock tables: 0=none, 1=per sync cycle, 2=per table, or 3=globally.

This uses "LOCK TABLES". This can help prevent tables being changed while you’re examiningthem.

是否锁表:0不锁;

1,只锁检查的块,检查完毕解锁,为下个块加锁

2,  加锁和解锁每单个要检查的表

3,  使用命令FLUSH TABLES WITH READ LOCK进行全局读锁定;
---------------------
作者:老王笔记
来源:CSDN
原文:https://blog.csdn.net/JSWANGCHANG/article/details/79501452
版权声明:本文为博主原创文章,转载请附上博文链接!

pt-table-sync笔记 - 默默前行 - CSDN博客 https://blog.csdn.net/JSWANGCHANG/article/details/79501452?utm_source=blogxgwz6

pt-table-sync 使用方法【转】的更多相关文章

  1. Oracle使用Sql把XML解析成表(Table)的方法

    SELECT * FROM XMLTABLE('$B/DEAL_BASIC/USER_DEAL_INFO' PASSING XMLTYPE('<?xml version="1.0&qu ...

  2. 汇总常用的jQuery操作Table tr td方法

    虽然现在DIV+CSS进行页的布局大行其道,但是很多地方使用table还是有很多优势,用table展示数据是比较方便的,下面汇总了jQuery操作Table tr td常用的方法,熟记这些操作技巧,下 ...

  3. mysqldump: Couldn't execute 'show table status '解决方法

    执行:[root@host2 lamp]# mysqldump -F -R -E --master-data=2   -p -A --single-transaction 在控制台端出现 mysqld ...

  4. thinkphp中SQLSTATE[42S02]: Base table or view not found: 1146 Table错误解决方法

    随手记录下今天在thinkphp3.2.3中遇到的错误SQLSTATE[42S02]: Base table or view not found: 1146 Table 'test.file_info ...

  5. Android使用Sugar ORM创建数据库报no such table:...的解决方法

    在学习使用Android开源框架Sugar ORM时,只是做了开始的创建数据库的操作就报出如下的异常信息 android.database.sqlite.SQLiteException: no suc ...

  6. Incorrect key file for table错误解决方法

    问题现象: alter table portal_app_xxxx_xxx add devno varchar(64) NOT NULL DEFAULT '' COMMENT '设备机编',add s ...

  7. bootstrap Table的使用方法

    1.官网 url:http://bootstrap-table.wenzhixin.net.cn/zh-cn/documentation/ 文档包含了表格属性.列属性.事件.方法等等. 2.引入库 只 ...

  8. lua中,两种json和table互转方法的效率比较

    lua中json和table的互转,是我们在平时开发过程中经常用到的.比如: 在用lua编写的服务器中,如果客户端发送json格式的数据,那么在lua处理业务逻辑的时候,必然需要转换成lua自己的数据 ...

  9. (转载)html中table的使用方法

      colspan表示该一储存格向右打通的栏数. rowspan表示该一储存格向下打通的栏数. colspan是表示横向合并单元格,colspan=“3”表示水平合并三个td rowspan是表示竖直 ...

  10. 对EJB返回的AaaryList显示到table的处理方法

      1. ArrayList --> Object[]        ArrayList x = new ArrayList();        int i = x.size();        ...

随机推荐

  1. 设计模式---接口隔离模式之适配器模式(Adapter)

    一:概念 通过Adapter模式可以改变已有类(或外部类)的接口形式 二:动机 在软件系统中,由于应用环境的变化,常常需要将“一些现存的对象”放在新的环境中应用,但是新环境要求的接口是这些现存对象所不 ...

  2. IIS 为应用程序池提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误的解决方法

    系统环境:Windows Server 2008 R2 64位, IIS 7.0 错误信息: 为应用程序池提供服务的进程在与 Windows Process Activation Service 通信 ...

  3. android studio导出apk

    在android studio导出的apk分为4种,一种是未签名调试版apk,一种是未签名发行版apk,一种是已签名调试版apk,还有一种是已签名发行版apk.以下将介绍这4种apk如何导出. 一.调 ...

  4. 利用spring的MultipartFile实现文件上传【原】

    利用spring的MultipartFile实现文件上传 主要依赖jar包 spring-web-3.0.6.RELEASE.jar 用到 (org.springframework.web.multi ...

  5. HDU 6432(不连续环排列 ~)

    题意是说在长度为 n 的环排列中,按照一定的方向(顺时针或逆时针),后一个数不能仅比前一个数大 1 , n 的下一个数不能是 1 ,问这种长度为 n 且本质不同(本质不同指环上数字的相对位置不同,如 ...

  6. Linux 下装逼技巧

    ``` 1.下载cmatrix-1.2a.tar.gz文件 [root@localhost ~]# wget https://jaist.dl.sourceforge.net/project/cmat ...

  7. Entity Framework 6.0 常见异常及解决办法

    Ø  简介 本文主要记录 EF(Entity Framework) 在平时的开发中可能遇到的异常,以及应该如何去解决. 1.   System.InvalidOperationException 1) ...

  8. luogu 1484\1792 种树 奇怪的贪心可反悔

    1484 种树 此版本是线性的,那么根据链表维护即可: 构建新点,点的左右分别是原整个区间的前驱及后继,再正常维护即可 注意两个版本的维护有所不同 第二个版本的维护直接将左右两点删除 1792 种树2 ...

  9. PHP文件系统管理

    文件概念: 第一个是windows的文件,另一个php根据LINUX的文件,两者是有所不同的,我们说的页面基于windows的文件可以是是文件夹(也就是目录)或是文件,而php两者都必须有,它包含目录 ...

  10. kindeditor编辑器上传图片

    使用的是asp.net MVC 上传图片. 1.下载Kindeditor的对应的包 2.html页面 @{ Layout = null; } <!DOCTYPE html> <htm ...