本文共 4835 字,大约阅读时间需要 16 分钟。
-- Sync db.tbl on host1 to host2:pt-table-sync --execute h=host1,D=db,t=tbl h=host2-- Sync all tables on host1 to host2 and host3:pt-table-sync --execute host1 host2 host3-- Make slave1 have the same data as its replication master:pt-table-sync --execute --sync-to-master slave1 # Resolve differences that pt-table-checksum found on all slaves of master1:pt-table-sync --execute --replicate test.checksum master1# Same as above but only resolve differences on slave1:pt-table-sync --execute --replicate test.checksum --sync-to-master slave1# Sync master2 in a master-master replication configuration, where master2’s copy of db.tbl is known or suspected to be incorrect:pt-table-sync --execute --sync-to-master h=master2,D=db,t=tbl# Note that in the master-master configuration, the following will NOT do what you want, because it will make changes directly on master2, which will then flow through replication and change master1’s data:#! Don't do this in a master-master setup!pt-table-sync --execute h=master1,D=db,t=tbl master2# 有主键或者唯一键,在主库进行 replace into 的操作pt-table-sync --execute h=192.168.3.26,u=root,p=zhujie1986,D=working,t=department,P=3306 --sync-to-master --verbose --verbose --charset=utf8 --print# 没主键或唯一键,直接在备库操作,要有超级用户权限pt-table-sync --execute h=192.168.3.25,u=root,p=zhujie1986,D=working,t=department,P=3306 h=192.168.3.26 --no-check-slave --verbose --verbose --charset=utf8 --print
FBI WARNING: pt-table-sync changes data! Before using this tool, please:Read the tool’s documentationReview the tool’s known “BUGS”Test the tool on a non-production serverBackup your production server and verify the backupspt-table-sync is mature, proven in the real world, and well tested, but if used improperly it can have adverse consequences. Always test syncing first with --dry-run and --print.
针对单向数据同步
匹配主库
if DSN has a t part, sync only that table: if 1 DSN: if --sync-to-master: The DSN is a slave. Connect to its master and sync. if more than 1 DSN: The first DSN is the source. Sync each DSN in turn.else if --replicate: if --sync-to-master: The DSN is a slave. Connect to its master, find records of differences, and fix. else: The DSN is the master. Find slaves and connect to each, find records of differences, and fix.else: if only 1 DSN and --sync-to-master: The DSN is a slave. Connect to its master, find tables and filter with --databases etc, and sync each table to the master. else: find tables, filtering with --databases etc, and sync each DSN to the first.
必须指定需要同步的数据库信息:
pt-table-sync --execute h=host1,u=msandbox,p=msandbox h=host2
host2 将会使用 host1的 u,p参数连接数据库
Replicas using row-based replicationpt-table-sync requires statement-based replication when used with the --sync-to-master or --replicate option. Therefore it will set binlog_format=STATEMENT on the master for its session if required. To do this user must have SUPER privilege.
pt-table-checksum --nocheck-binlog-format --nocheck-replication-filters --replicate=percona.checksums --set-vars innodb_lock_wait_timeout=50 --host=192.168.3.25 --port=3306 --user=root --password=zhujie1986 --databases working --tables department --replicate-check TS ERRORS DIFFS ROWS CHUNKS SKIPPED TIME TABLE01-18T14:58:11 0 1 7 1 0 0.009 working.departmentpt-table-sync --execute h=192.168.3.25,u=root,p=zhujie1986,D=working,t=department,P=3306 h=192.168.3.26 --no-check-slave --verbose --charset=utf8# Syncing A=utf8,D=working,P=3306,h=192.168.3.26,p=...,t=department,u=root# DELETE REPLACE INSERT UPDATE ALGORITHM START END EXIT DATABASE.TABLE# 0 0 7 0 GroupBy 14:59:28 14:59:28 2 working.department
- --verbose:输出差异数据处理信息,--verbose --verbose 输出块信息- --print:输出处理 SQL语句- --charset=utf8:设置编码,主要针对插入- --no-check-slave:直接在备库插入,需要超级用户权限
Chunk
转载地址:http://qbggo.baihongyu.com/