Home Database Mysql Tutorial pt-table-checksum verification and pt-table-sync repair data

pt-table-checksum verification and pt-table-sync repair data

Jun 23, 2017 pm 03:06 PM
repair data check

1: Download tool package
Log in to the website to download the corresponding tool package
2: Installation
(1) yum installation:
sudo yum install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm
yum list | grep percona-toolkit
Copy after login

The result set shows the following to prove that the installation is successful:

percona-toolkit.noarch 3.0.0-rc percona-release-noarch
Copy after login

Then install

sudo yum install percona-toolkit
Copy after login

(2) Unzip the installation package:

[root@localhost home]# cd toolkit/[root@localhost toolkit]# ls
percona-toolkit-2.2.19.tar.gz[root@localhost toolkit]# tar -xvf percona-toolkit.tar.gz
Copy after login

So far, percona's toolKit toolkit has been installed. Let's mainly test pt-table-checksum verification and pt-table-sync. The former is mainly used for data verification to verify whether the master and slave are consistent. The latter is mainly used To repair data, the two can generally be used together to repair data inconsistencies.

pt-table-checksum is a tool provided by percona to verify the consistency of master-slave data. We point to the master library and judge the result set of the slave library and feedback it to us. When inconsistencies are captured When asked, a non-zero result will be returned. However, it can only find inconsistencies in the data. If you want to repair data problems, you must use pt-table-sync.
pt-table-checksum is based on the statement copy format when running. If we are in ROW format, we need to add the --no-check-binlog-format parameter when executing.
3: The practice of pt-table-checksum, we can use it directly after installation. I am using the second method
[root@localhost bin]# /home/toolkit/percona-toolkit-2.2.19/bin/pt-table-checksum --nocheck-replication-filters --replicate=rep_test.checksums --no-check-binlog-format h=172.16.16.35,u=root,p=123456,P=3306TS ERRORS DIFFS ROWS CHUNKS SKIPPED TIME TABLE06-07T10:55:49 0 0 1 1 0 1.331 MAXIANGQIAN.MAXIANGQIAN06-07T10:55:54 0 0 1 1 0 5.524 maxiangqian.test06-07T10:55:56 0 0 4 1 0 1.208 maxiangqian.test0106-07T10:55:57 0 0 0 1 0 1.164 mysql.columns_priv06-07T10:55:58 0 0 5 1 0 1.216 mysql.db06-07T10:55:59 0 0 2 1 0 1.176 mysql.engine_cost06-07T10:56:00 0 0 0 1 0 1.178 mysql.event06-07T10:56:01 0 0 0 1 0 1.160 mysql.func06-07T10:56:03 0 0 1 1 0 1.154 mysql.gtid_executed06-07T10:56:08 0 0 40 4 0 5.015 mysql.help_category06-07T10:56:13 0 0 679 5 0 5.806 mysql.help_keyword06-07T10:56:18 0 0 1334 4 0 4.572 mysql.help_relation06-07T10:56:19 0 0 635 1 0 1.169 mysql.help_topic06-07T10:56:20 0 0 0 1 0 1.163 mysql.ndb_binlog_index06-07T10:56:22 0 0 0 1 0 1.157 mysql.plugin06-07T10:56:23 0 1 48 1 0 1.236 mysql.proc06-07T10:56:24 0 0 0 1 0 1.197 mysql.procs_priv06-07T10:56:25 0 0 1 1 0 1.235 mysql.proxies_priv06-07T10:56:26 0 0 6 1 0 1.188 mysql.server_cost06-07T10:56:28 0 0 0 1 0 1.154 mysql.servers06-07T10:56:34 0 0 1 1 0 6.184 mysql.tables_priv06-07T10:56:35 0 0 0 1 0 1.198 mysql.time_zone06-07T10:56:36 0 0 0 1 0 1.121 mysql.time_zone_leap_second06-07T10:56:37 0 0 0 1 0 1.148 mysql.time_zone_name06-07T10:56:38 0 0 0 1 0 1.147 mysql.time_zone_transition06-07T10:56:40 0 0 0 1 0 1.138 mysql.time_zone_transition_type06-07T10:56:41 0 0 8 1 0 1.336 mysql.user06-07T10:56:42 0 0 0 1 0 1.164 open_api.ma06-07T10:57:01 0 0 1000000 13 0 18.707 sbtest.sbtest06-07T10:57:02 0 0 6 1 0 1.263 sys.sys_config
Copy after login

We can also check a certain library separately to narrow the scope of the check:

[root@localhost bin]# /home/toolkit/percona-toolkit-2.2.19/bin/pt-table-checksum --nocheck-replication-filters --replicate=rep_test.checksums --no-check-binlog-format --databases=maxiangqian h=172.16.16.35,u=root,p=123456,P=3306
Copy after login

The results obtained are as above, take a look at the description :

TS: Time to complete the check. ERRORS: The number of errors and warnings that occurred during the check. DIFFS: 0 means consistent, 1 means inconsistent. When --no-replicate-check is specified, it will always be 0. When --replicate-check-only is specified, different information will be displayed. ROWS: The number of rows in the table. CHUNKS: The number of blocks divided into the table. SKIPPED: The number of blocks to skip due to errors or warnings or because they are too large. TIME: execution time. TABLE: The name of the table being checked.
Then take a look at this main parameter:
--nocheck-replication-filters :不检查复制过滤器,建议启用。后面可以用--databases来指定需要检查的数据库。--no-check-binlog-format : 不检查复制的binlog模式,要是binlog模式是ROW,则会报错。--replicate-check-only :只显示不同步的信息。 --replicate= :把checksum的信息写入到指定表中,建议直接写到被检查的数据库当中。 --databases= :指定需要被检查的数据库,多个则用逗号隔开。--tables= :指定需要被检查的表,多个用逗号隔开 h=127.0.0.1 :Master的地址
u=root :用户名
p=123456 :密码
P=3306 :端口
Copy after login

By specifying the --replicate=rep_test.checksums parameter, a database will be automatically generated. The check information All are written to the checksums table.

Enter the corresponding library of SLAVE to view the information of the checksums table. You can view inconsistent information through the following statement:
mysql> select * from checksums where this_cnt<>master_cnt;
Copy after login

Through the above this_crc <> master_crc can more clearly see their inconsistencies. Through chunk, we can know which block of this table has inconsistent records.

4: Detect data inconsistencies and use pt-table-sync to repair
Let’s take a look at the previous section. We detected that there is an inconsistency through the following statement The data is inconsistent:
[root@localhost bin]# /home/toolkit/percona-toolkit-2.2.19/bin/pt-table-checksum --nocheck-replication-filters --replicate=rep_test.checksums --no-check-binlog-format --databases=maxiangqian h=172.16.16.35,u=root,p=123456,P=3306TS ERRORS DIFFS ROWS CHUNKS SKIPPED TIME TABLE06-07T11:13:18 0 0 1 1 0 1.220 MAXIANGQIAN.MAXIANGQIAN06-07T11:13:19 0 1 1 1 0 1.135 maxiangqian.test06-07T11:13:21 0 0 4 1 0 1.197 maxiangqian.test01
Copy after login

Restore inconsistent data:

[root@localhost bin]# clear[root@localhost bin]# ./pt-table-sync --execute h=172.16.16.35,P=3306,D=maxiangqian,t=test,u=root,p=123456 h=172.16.16.34,P=3306,u=root,p=123456 --no-check-slave --print[root@localhost bin]# /home/toolkit/percona-toolkit-2.2.19/bin/pt-table-checksum --nocheck-replication-filters --replicate=rep_test.checksums --no-check-binlog-format --databases=maxiangqian h=172.16.16.35,u=root,p=123456,P=3306TS ERRORS DIFFS ROWS CHUNKS SKIPPED TIME TABLE06-07T11:18:09 0 0 1 1 0 1.172 MAXIANGQIAN.MAXIANGQIAN06-07T11:18:10 0 0 1 1 0 1.144 maxiangqian.test06-07T11:18:11 0 0 4 1 0 1.282 maxiangqian.test01
Copy after login

itself, the test table is missing a row of data, After execution, the data of the subject and the copy will be consistent:

Next, let’s take a look at some use cases of pt-table-sync:
(1) Put host1 on Synchronize the data to host2, only synchronize the db.tbl table
pt-table-sync --execute h=host1,D=db,t=tbl h=host2[root@localhost bin]# ./pt-table-sync --execute h=172.16.16.35,P=3306,D=maxiangqian,t=test,u=root,p=123456 h=172.16.16.34,P=3306,u=root,p=123456 --no-check-slave --print
Copy after login

(2) Synchronize all data on host1 to host2 and host3

pt-table-sync --execute host1 host2 host3[root@localhost bin]# ./pt-table-sync --execute h=172.16.16.35,P=3306,D=maxiangqian,t=test,u=root,p=123456 h=172.16.16.34,P=3306,u=root,p=123456 h=172.16.16.35,P=3307,u=root,p=123456 --no-check-slave --print
Copy after login

(3) Ensure that all data on slave1 is synchronized with the main database

pt-table-sync --execute --sync-to-master slave1[root@localhost bin]# ./pt-table-sync --execute --sync-to-master h=172.16.16.34,P=3306,u=root,p=123456 --no-check-slave --print
Copy after login

This requirement checks The table must have a primary key or unique index. We can also specify the single table of a single database as follows

[root@localhost bin]# ./pt-table-sync --execute --sync-to-master h=172.16.16.34,P=3306,D=maxiangqian,t=test01,u=root,p=123456 --no-check-slave --print
Copy after login

(4) Restore all slave libraries according to the rep_test.checksums generated by the check

pt-table-sync --execute --replicate test.checksum master1
Copy after login

That is the following example:

[root@localhost bin]# ./pt-table-sync --execute --replicate rep_test.checksums h=172.16.16.35,P=3306,u=root,p=123456
Copy after login

(5) Only repair the data of slave1

/pt-table-sync --execute --replicate rep_test.checksums --sync-to-master slave1
Copy after login

(6) Dual master mode master2 repairs its own data:

pt-table-sync --execute --sync-to-master h=master2,D=db,t=tbl
Copy after login

Due to dual master mode There are many problems. A modification may be transmitted to another database, so we must not perform the following operations in dual-master mode:

pt-table-sync --execute h=master1,D=db,t=tbl master2
Copy after login

The above is the detailed content of pt-table-checksum verification and pt-table-sync repair data. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1672
14
PHP Tutorial
1277
29
C# Tutorial
1257
24
This Apple ID is not yet in use in the iTunes Store: Fix This Apple ID is not yet in use in the iTunes Store: Fix Jun 10, 2024 pm 05:42 PM

When logging into iTunesStore using AppleID, this error saying "This AppleID has not been used in iTunesStore" may be thrown on the screen. There are no error messages to worry about, you can fix them by following these solution sets. Fix 1 – Change Shipping Address The main reason why this prompt appears in iTunes Store is that you don’t have the correct address in your AppleID profile. Step 1 – First, open iPhone Settings on your iPhone. Step 2 – AppleID should be on top of all other settings. So, open it. Step 3 – Once there, open the “Payment & Shipping” option. Step 4 – Verify your access using Face ID. step

Use ddrescue to recover data on Linux Use ddrescue to recover data on Linux Mar 20, 2024 pm 01:37 PM

DDREASE is a tool for recovering data from file or block devices such as hard drives, SSDs, RAM disks, CDs, DVDs and USB storage devices. It copies data from one block device to another, leaving corrupted data blocks behind and moving only good data blocks. ddreasue is a powerful recovery tool that is fully automated as it does not require any interference during recovery operations. Additionally, thanks to the ddasue map file, it can be stopped and resumed at any time. Other key features of DDREASE are as follows: It does not overwrite recovered data but fills the gaps in case of iterative recovery. However, it can be truncated if the tool is instructed to do so explicitly. Recover data from multiple files or blocks to a single

Open source! Beyond ZoeDepth! DepthFM: Fast and accurate monocular depth estimation! Open source! Beyond ZoeDepth! DepthFM: Fast and accurate monocular depth estimation! Apr 03, 2024 pm 12:04 PM

0.What does this article do? We propose DepthFM: a versatile and fast state-of-the-art generative monocular depth estimation model. In addition to traditional depth estimation tasks, DepthFM also demonstrates state-of-the-art capabilities in downstream tasks such as depth inpainting. DepthFM is efficient and can synthesize depth maps within a few inference steps. Let’s read about this work together ~ 1. Paper information title: DepthFM: FastMonocularDepthEstimationwithFlowMatching Author: MingGui, JohannesS.Fischer, UlrichPrestel, PingchuanMa, Dmytr

Comprehensive Guide to PHP 500 Errors: Causes, Diagnosis and Fixes Comprehensive Guide to PHP 500 Errors: Causes, Diagnosis and Fixes Mar 22, 2024 pm 12:45 PM

A Comprehensive Guide to PHP 500 Errors: Causes, Diagnosis, and Fixes During PHP development, we often encounter errors with HTTP status code 500. This error is usually called &quot;500InternalServerError&quot;, which means that some unknown errors occurred while processing the request on the server side. In this article, we will explore the common causes of PHP500 errors, how to diagnose them, and how to fix them, and provide specific code examples for reference. Common causes of 1.500 errors 1.

Google is ecstatic: JAX performance surpasses Pytorch and TensorFlow! It may become the fastest choice for GPU inference training Google is ecstatic: JAX performance surpasses Pytorch and TensorFlow! It may become the fastest choice for GPU inference training Apr 01, 2024 pm 07:46 PM

The performance of JAX, promoted by Google, has surpassed that of Pytorch and TensorFlow in recent benchmark tests, ranking first in 7 indicators. And the test was not done on the TPU with the best JAX performance. Although among developers, Pytorch is still more popular than Tensorflow. But in the future, perhaps more large models will be trained and run based on the JAX platform. Models Recently, the Keras team benchmarked three backends (TensorFlow, JAX, PyTorch) with the native PyTorch implementation and Keras2 with TensorFlow. First, they select a set of mainstream

Slow Cellular Data Internet Speeds on iPhone: Fixes Slow Cellular Data Internet Speeds on iPhone: Fixes May 03, 2024 pm 09:01 PM

Facing lag, slow mobile data connection on iPhone? Typically, the strength of cellular internet on your phone depends on several factors such as region, cellular network type, roaming type, etc. There are some things you can do to get a faster, more reliable cellular Internet connection. Fix 1 – Force Restart iPhone Sometimes, force restarting your device just resets a lot of things, including the cellular connection. Step 1 – Just press the volume up key once and release. Next, press the Volume Down key and release it again. Step 2 – The next part of the process is to hold the button on the right side. Let the iPhone finish restarting. Enable cellular data and check network speed. Check again Fix 2 – Change data mode While 5G offers better network speeds, it works better when the signal is weaker

Tesla robots work in factories, Musk: The degree of freedom of hands will reach 22 this year! Tesla robots work in factories, Musk: The degree of freedom of hands will reach 22 this year! May 06, 2024 pm 04:13 PM

The latest video of Tesla's robot Optimus is released, and it can already work in the factory. At normal speed, it sorts batteries (Tesla's 4680 batteries) like this: The official also released what it looks like at 20x speed - on a small "workstation", picking and picking and picking: This time it is released One of the highlights of the video is that Optimus completes this work in the factory, completely autonomously, without human intervention throughout the process. And from the perspective of Optimus, it can also pick up and place the crooked battery, focusing on automatic error correction: Regarding Optimus's hand, NVIDIA scientist Jim Fan gave a high evaluation: Optimus's hand is the world's five-fingered robot. One of the most dexterous. Its hands are not only tactile

How to fix the volume cannot be adjusted in WIN10 How to fix the volume cannot be adjusted in WIN10 Mar 27, 2024 pm 05:16 PM

1. Press win+r to open the run window, enter [regedit] and press Enter to open the registry editor. 2. In the opened registry editor, click to expand [HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRun]. In the blank space on the right, right-click and select [New - String Value], and rename it to [systray.exe]. 3. Double-click to open systray.exe, modify its numerical data to [C:WindowsSystem32systray.exe], and click [OK] to save the settings.

See all articles