• MySQL数据库主从数据对比


     

    1. 工具安装

    使用percona-Toolkit进行数据对比,因此先进行此工具的安装
    官方地址:
    https://www.percona.com/downloads/percona-toolkit
    安装依赖包
    yum install -y perl-DBI  perl-DBD-MySQL   perl-Time-HiRes  perl-IO-Socket-SSL perl-TermReadKey
    安装
    rpm  -ivh  percona-toolkit-3.0.4-1.el6.x86_64.rpm

    2.数据对比

    pt-table-checksum  --host=127.0.0.1--port 3306 --databases=test1 -uroot -ppass   --no-check-binlog-format

    过程如下:

    [root@mysql1 ~]# pt-table-checksum  --host=127.0.0.1 --port 3346 --databases=test1 -uroot -ppass   --no-check-binlog-format
    Diffs cannot be detected because no slaves were found.  Please read the --recursion-method documentation for information.
    # A software update is available:
                TS ERRORS  DIFFS     ROWS  CHUNKS SKIPPED    TIME TABLE
    08-19T00:05:20      0      0     9759       4       0   0.742 test1.COST_RISKFREE
    08-19T00:05:20      0      0    17862       1       0   0.349 test1.FFUT_QUOTATION
    08-19T00:05:27      0      0   461012      12       0   6.714 test1.STK_MKT_QUOTATION
    08-19T00:05:27      0      0       20       1       0   0.177 test1.e
    08-19T00:05:27      0      0        1       1       0   0.171 test1.heartbeat
    08-19T00:05:28      0      0        1       1       0   0.175 test1.test_int
    You have new mail in /var/spool/mail/root

    简介:

    TS            :完成检查的时间。
    ERRORS        :检查时候发生错误和警告的数量。
    DIFFS         :0表示一致,1表示不一致。当指定--no-replicate-check时,会一直为0,当指定--replicate-check-only会显示不同的信息。
    ROWS          :表的行数。
    CHUNKS        :被划分到表中的块的数目。
    SKIPPED       :由于错误或警告或过大,则跳过块的数目。
    TIME          :执行的时间。
    TABLE         :被检查的表名

    如出现DIFFS不为0 的情况,即对应表主从数据不一致

    3.数据修复

    修复时使用pt-table-sync工具
    pt-table-sync --execute  --databases=test1  --tables=COST_RISKFREE   --replicate percona.checksums --sync-to-master  h=106.14.184.46,u=root,p=123456
    # TableChecksum:4998 5214 SELECT db, tbl, CONCAT(db, '.', tbl) AS `table`, chunk, chunk_index, lower_boundary, upper_boundary, COALESCE(this_cnt-master_cnt, 0) AS cnt_diff, COALESCE(this_crc <> master_crc OR ISNULL(master_crc) <> ISNULL(this_crc), 0) AS crc_diff, this_cnt, master_cnt, this_crc, master_crc FROM percona.checksums WHERE master_cnt <> this_cnt OR master_crc <> this_crc OR ISNULL(master_crc) <> ISNULL(this_crc)
    # TableChecksum:4998 5214 SELECT db, tbl, CONCAT(db, '.', tbl) AS `table`, chunk, chunk_index, lower_boundary, upper_boundary, COALESCE(this_cnt-master_cnt, 0) AS cnt_diff, COALESCE(this_crc <> master_crc OR ISNULL(master_crc) <> ISNULL(this_crc), 0) AS crc_diff, this_cnt, master_cnt, this_crc, master_crc FROM percona.checksums WHERE master_cnt <> this_cnt OR master_crc <> this_crc OR ISNULL(master_crc) <> ISNULL(this_crc)
    # SchemaIterator:7923 5214 Table heartbeat is not in --tables list, ignoring
    # pt_table_sync:10262 5214 No checksum differences
    # pt_table_sync:11128 5214 Disconnected dbh DBI::db=HASH(0x2c229e0)
    # pt_table_sync:11128 5214 Disconnected dbh DBI::db=HASH(0x25c18e0)
    # pt_table_sync:11128 5214 Disconnected dbh DBI::db=HASH(0x25c1e80)
    # pt_table_sync:11128 5214 Disconnected dbh DBI::db=HASH(0x25c1610)
     
  • 相关阅读:
    Python 处理时间的模块
    C# 委托在线程与UI界面之间的应用
    C# 自己动手实现Spy++(二)
    C# 自己动手实现Spy++(一)
    VS2008自定义快捷键设置
    C#深入解析委托——C#中为什么要引入委托
    C# 线程 在 sleep,suspend 之后 Abort 的方法
    C#多线程学习笔记之(abort与join配合使用)
    使用命名管道的OVERLAPPED方式实现非阻塞模式编程 .
    C++和C#进程之间通过命名管道通信(上)
  • 原文地址:https://www.cnblogs.com/gjc592/p/15170543.html
Copyright © 2020-2023  润新知