From the master data check
Dimensions:
A month to do a check on the existing data network data
If there is a main switch from day to do a data check
Verification tools:
pt-table-checksum
Repair Tool:
pt-table-sync
pt-table-checksum
principle
Create a table in the database: checksums
Each taking count (*) where id> 0 and id <= 1000 data (this_cnt), do hash_code operation (this_crc)
主库:select count(*) from tb where id > 0 and id <= 1000;
Master and slave functions are performed, generate respective CNT, the value of the crc
set binlog_format = 'statement'
replace into percona.checksum( db, tb1, chunk, chunk_index, lower_boundary, upper_boundary, this_cnt, this_crc) select xxxxxx
The this_cnt, this_crc value of the main library updated to master_cnt, master_crc years.
select this_cnt, this_crc from checksum where db = 'xx' and tb = 'xx' and chunk = xx;
update checksum set master_cnt = this_cnt.value, master_crc = this_crc.value where db = 'xx' and tb = 'xx' and chunk = xx;
From comparison this_cnt library, this_crc value master_cnt, master_crc
select db,tb1,sum(this_cnt) as total_rows, count(*) as chunks from checksums where (master_cnt <>this_cnt or master_crc <> this_crc or isnull(master_crc) <> isnull(this_crc)) group by db,tb1;
use
--recursion-method=hosts:
We need to add information from the library from the library configuration file:
report_host=172.18.10.198
When the main library show slave hosts, will be able to find from the library.
pt-table-checksum --host=172.18.10.197 --port=3306 --databases=xxxx -uxxxx -p --nocheck-replication-filters --replicate=percona.checksums --nocheck-binlog-format --nocheck-plan --recursion-method=hosts
--nocheck-replication-filters: copy does not check the filter is recommended to enable. --Databases can be specified later to check database.
--no-check-binlog-format: Do not check binlog replication mode, and if binlog mode is ROW, it will error.
--replicate-check-only: show only the information is not synchronized.
--replicate =: writing information to the checksum of the specified table, which is recommended to write directly to check the database.
--databases =: Specifies the database needs to be checked, the plurality of separated by commas.
--tables =: Specifies the table needs to be checked, a plurality of separated by commas
h = 127.0.0.1: Master Address
u = root: Username
p = 123456: password
P = 3306: Port
TS: time check is completed.
ERRORS: the number of errors and warnings occur when checking.
DIFFS: 0 expressed unanimous, 1 inconsistent. When specifying --no-replicate-check, it would have been zero, when the designated --replicate-check-only displays different information.
ROWS: the number of rows in the table.
CHUNKS: is divided into the number of blocks in the table.
SKIPPED: due to error or warning or too large, the number of blocks is skipped.
TIME: time of execution.
TABLE: checked table name.
pt-table-sync
principle
Pt-table_checksum error found by the chunk, conduct a binary search to find the error log.
Main library settings
binlog_format='statement'
In the main inventory, from the library does not exist. Primary library to perform delete from tb where id = xxx;
In the main stock from inventory in the main library replace into, reinsert the record once. Library will insert into the correct data.
use
Data Recovery: h is a first master, h is the second slave, the table must have a primary key. View and then perform the first --print
Print SQL
pt-table-sync --charset=utf8 --databases --no-check-slave dsn=u=root,p=root,h=172.18.10.198,P=3306 dsn=u=root,p=root,h=172.18.10.198,P=3307 --print
carried out
pt-table-sync --charset=utf8 --databases=db1 --no-check-slave dsn=u=root,p=root,h=172.18.10.198,P=3306 dsn=u=root,p=root,h=172.18.10.198,P=3307 --execute
--ignore-databases = specify to ignore library
--databases = specified library
--tables = specified table
--print view the execution statement
--execute execution
--no-check-slave does not check whether the desitination from the library