pt-table-sync 使用介绍

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介: pt-table-sync 使用介绍

pt-table-sync:对两个库不一致的数据进行同步,他能够自动发现两个实例间不一致的数据,然后进行sync操作,pt-table-sync无法同步表结构,和索引等对象,只能同步数据

一、表没有主键
--print
./pt-table-sync --ignore-databases=mysql,sys --no-check-slave dsn=u=checkq,p=123456,h=192.168.56.108,P=3306 dsn=u=checkq,p=123456,h=192.168.56.101,P=3306 --databases=bhs --tables=pp --print
INSERT INTO bhs.pp(id, name) VALUES ('1', 'ee') /percona-toolkit src_db:bhs src_tbl:pp src_dsn:P=3306,h=192.168.56.108,p=...,u=checkq dst_db:bhs dst_tbl:pp dst_dsn:P=3306,h=192.168.56.101,p=...,u=checkq lock:0 transaction:1 changing_src:0 replicate:0 bidirectional:0 pid:3704 user:root host:managed/;

--execute
./pt-table-sync --ignore-databases=mysql,sys --no-check-slave h=192.168.56.108,u=checkq,p=123456,P=3306 h=192.168.56.101,u=checkq,p=123456,P=3306 --databases=bhs --tables=pp --execute --print
INSERT INTO bhs.pp(id, name) VALUES ('1', 'ee') /percona-toolkit src_db:bhs src_tbl:pp src_dsn:P=3306,h=192.168.56.108,p=...,u=checkq dst_db:bhs dst_tbl:pp dst_dsn:P=3306,h=192.168.56.101,p=...,u=checkq lock:0 transaction:1 changing_src:0 replicate:0 bidirectional:0 pid:3747 user:root host:managed/;

二、表有主键

--print
./pt-table-sync --sync-to-master --charset=utf8 --ignore-databases=mysql,sys --no-check-slave h=192.168.56.101,u=checkq,p=123456,P=3306 --databases=bhs --tables=test --print
REPLACE INTO bhs.test(id, name) VALUES ('3', 'd') /percona-toolkit src_db:bhs src_tbl:test src_dsn:A=utf8,P=3306,h=192.168.56.108,p=...,u=checkq dst_db:bhs dst_tbl:test dst_dsn:A=utf8,P=3306,h=192.168.56.101,p=...,u=checkq lock:1 transaction:1 changing_src:1 replicate:0 bidirectional:0 pid:3768 user:root host:managed/;

./pt-table-sync --execute --sync-to-master --charset=utf8 --ignore-databases=mysql,sys --no-check-slave h=192.168.56.101,u=checkq,p=123456,P=3306 --databases=bhs --tables=test --print
REPLACE INTO bhs.test(id, name) VALUES ('3', 'd') /percona-toolkit src_db:bhs src_tbl:test src_dsn:A=utf8,P=3306,h=192.168.56.108,p=...,u=checkq dst_db:bhs dst_tbl:test dst_dsn:A=utf8,P=3306,h=192.168.56.101,p=...,u=checkq lock:1 transaction:1 changing_src:1 replicate:0 bidirectional:0 pid:3775 user:root host:managed/;

相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
打赏
0
0
0
0
2
分享
相关文章
pt-tools系列:pt-online-schema-change 最佳实践
pt的详细步骤 Step 1: Create the new table. Step 2: Alter the new, empty table. This should be very quick, or die if the user specified a bad alter statement.
5225 0
pt-table-checksum原理详解
环境 MySQL: MySQL 5.6.27 OS: centos 6.6 tool: pt-table-checksum 2.2.15 它能做什么 业界最流行的MySQL主从数据对比工具,数据一致性检测最好的的工具,没有之一 如何使用 ./pt-table-che
7590 0
pwnable passcode 10pt
题目在 ssh passcode@pwnable.kr -p2222 (pw:guest) 先看passcode.c: #include #include void login(){ int ...
902 0
Implementation of Global Temp Table
作者| 曾文旌阿里云数据库高级技术专家
406 0
Implementation of Global Temp Table
[WorkLog] InnoDB Faster truncate/drop table space
这个系列, 介绍upstream 一些有意思的worklog **问题** 在InnoDB 现有的版本里面, 如果一个table space 被truncated 或者 drop 的时候, 比如有一个连接创建了临时表, 连接断开以后, 对应的临时表都需要进行drop 操作. InnoDB 是需要将该tablespace 对应的所有的page 从LRU/FLUSH li
474 0
pt-table-checksum
pt-table-checksum是目前可以说是最好的查看主从一致性的工具 先来个使用例子,有助快速上手使用 在主库执行:mysql>GRANT SELECT, PROCESS, SUPER, REPLICATION SLAVE,CREATE,DELETE,INSERT,UPDATE ON .
1773 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等