Pt-table-sync Common referenc
Pt-table-sync is an excellent tool to solve the inconsistency between master and slave data. It can also be used to synchronize data between two non-master-slave databases. Ddl cannot be synchronized, but data can only be synchronized. The following are common examples:
Where hackers 192.168.56.101 is the source end, and hackers 192.168.56.102 is the destination side:
1.sync two separate databases, no master-slave replication relationship, synchronize all tables in the database, and exclude specific databases:
Pt-table-sync-- charset=utf8-- ignore-databases=mysql,sys upright admin dsn=u=admin,p=admin,h=192.168.56.103,P=3306-- execute-- print
If master-slave can be used-- no-check-slave ignores master-slave relationship, it is recommended that you first use-- print to see if there are any inconsistencies, and then use-- execute to synchronize:
Print out inconsistent data:
Pt-table-sync-- charset=utf8-- ignore-databases=mysql,sys-- no-check-slave upright admin dsn=u=admin,p=admin,h=192.168.56.102,P=3306 print
Synchronize the data and print out the synchronization statement:
Pt-table-sync-- charset=utf8-- ignore-databases=mysql,sys-- no-check-slave upright admin dsn=u=admin,p=admin,h=192.168.56.102,P=3306 execute-- print
Synchronize the specified library or table
Only data sync is performed on the specified library:
Pt-table-sync-- charset=utf8-- ignore-databases=mysql,sys-- databases=data upright admin dsn=u=admin,p=admin,h=192.168.56.102,P=3306 execute-- print
Data sync is performed on only the specified tables, with multiple tables separated by commas:
Pt-table-sync-- charset=utf8-- ignore-databases=mysql,sys-- databases=data-- tables=t_shop_order,t_shop_order_detail upright admin dsn=u=admin,p=admin,h=192.168.56.102,P=3306 execute-- print
-- tables can also use database names and tables:
-- tables=database_name.table_name
Ignore some libraries or ignore some tables
-- ignore-databases= specifies the libraries to ignore
-- ignore-tables=database_name.table_name specifies the table to ignore
3. If it is a master-slave replication, you can add-- sync-to-master parameter to sync the data:
The tables that need to be synchronized have primary keys or unique keys, of which 192.168.56.102 is the standby database:
Pt-table-sync-- sync-to-master-- charset=utf8-- ignore-databases=mysql,sys upright admins, packs admins, pamphlets, 192.168.56.102, execute 3306-- print.
Sync synchronizes multiple slave repositories, of which hackers 192.168.56.102 and hackers 192.168.56.103 are backup libraries:
Pt-table-sync-- sync-to-master-- charset=utf8-- ignore-databases=mysql,sys upright adminary execute-- print 192.168.56.102 pamphlet 3306
4.pt-table-sync help instructions:
Pt-table-sync-help