<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          MySQL數(shù)據(jù)庫主從數(shù)據(jù)對比及修復(fù)

          共 3663字,需瀏覽 8分鐘

           ·

          2021-08-22 12:58

          點(diǎn)擊上方藍(lán)字關(guān)注我

          MySQL主從數(shù)據(jù)不一致是比較常見的情況,如何對比,如何修復(fù)是DBA必知必會的一項熟練的技能。

          1、工具安裝

          使用percona-Toolkit進(jìn)行數(shù)據(jù)對比,因此先進(jìn)行此工具的安裝

          官方地址:

          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. 數(shù)據(jù)對比

          數(shù)據(jù)對比工具使用pt-table-checksum 進(jìn)行主從數(shù)據(jù)對比,可以參考如下命令

          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 :檢查時候發(fā)生錯誤和警告的數(shù)量。
          DIFFS :0表示一致,1表示不一致。當(dāng)指定
          --no-replicate-check時,會一直為0,當(dāng)指定--replicate-check-only會顯示不同的信息。
          ROWS :表的行數(shù)。
          CHUNKS :被劃分到表中的塊的數(shù)目。
          SKIPPED :由于錯誤或警告或過大,則跳過塊的數(shù)目。
          TIME :執(zhí)行的時間。
          TABLE :被檢查的表名

          如出現(xiàn)DIFFS不為0 的情況,即對應(yīng)表主從數(shù)據(jù)不一致

          3. 數(shù)據(jù)修復(fù)

          如果出現(xiàn)主從數(shù)據(jù)不一致的情況,則需要進(jìn)行數(shù)據(jù)修復(fù),修復(fù)的方式通常是通過主庫的數(shù)據(jù)修復(fù)從庫。修復(fù)時使用pt-table-sync工具進(jìn)行處理,案例如下:

          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)
          完成后,可以再次進(jìn)行檢測是否修復(fù)完畢。
          往期精彩回顧

          1.  MySQL高可用之MHA集群部署

          2.  mysql8.0新增用戶及加密規(guī)則修改的那些事

          3.  比hive快10倍的大數(shù)據(jù)查詢利器-- presto

          4.  監(jiān)控利器出鞘:Prometheus+Grafana監(jiān)控MySQL、Redis數(shù)據(jù)庫

          5.  PostgreSQL主從復(fù)制--物理復(fù)制

          6.  MySQL傳統(tǒng)點(diǎn)位復(fù)制在線轉(zhuǎn)為GTID模式復(fù)制

          7.  MySQL敏感數(shù)據(jù)加密及解密

          8.  MySQL數(shù)據(jù)備份及還原(一)

          9.  MySQL數(shù)據(jù)備份及還原(二)

          掃碼關(guān)注     
          瀏覽 35
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  日韩无码经典高清视频 | 女人天堂AV | 91 黄网站在线观看 | 大美女大香蕉网页 | 国产日韩欧美一级电影 |