当前位置: 首页 > news >正文

【MySQL工具】my2sql-快速解析binlog

​​​​​​

目录

​​​​​​

安装

my2sql简介

用途

工具优势

限制

账号所需权限

参数解析

场景

场景1 回滚

场景2 生成正向SQL

场景3 DML与事务统计

场景4 解析本地

与binlog2sql性能对比


安装

安装比较简单 直接下载二进制命令即可使用

wget https://github.com/liuhr/my2sql/raw/master/releases/centOS_release_7.x/my2sql

my2sql简介

go版MySQL binlog解析工具,通过解析MySQL binlog ,可以生成原始SQL、回滚SQL、去除主键的INSERT SQL等,也可以生成DML统计信息。类似工具有binlog2sql、MyFlash、my2fback等。

用途

  • 数据快速回滚(闪回)
  • 主从切换后新master丢数据的修复
  • 从binlog生成标准SQL,带来的衍生功能
  • 生成DML统计信息,可以找到哪些表更新的比较频繁
  • IO高TPS高, 查出哪些表在频繁更新
  • 找出某个时间点数据库是否有大事务或者长事务
  • 主从延迟,分析主库执行的SQL语句
  • 除了支持常规数据类型,对大部分工具不支持的数据类型做- 了支持,比如json、blob、text、emoji等数据类型sql生成

工具优势

功能丰富,参考上文

基于golang实现,速度快,全量解析1.1Gbinlog只需要1分30秒左右,当前其他类似开源工具一般要几十分钟

限制

  • 使用回滚/闪回功能时,binlog格式必须为row,且binlog_row_image=full, DML统计以及大事务分析不受影响
  • 只能回滚DML, 不能回滚DDL
  • 支持指定-tl时区来解释binlog中time/datetime字段的内容。开始时间-start-datetime与结束时间-stop-datetime也会使用此指定的时区, 但注意此开始与结束时间针对的是binlog event header中保存的unix timestamp。结果中的额外的datetime时间信息都是binlog event header中的unix timestamp
  • 此工具是伪装成从库拉取binlog,需要连接数据库的用户有SELECT, REPLICATION SLAVE, REPLICATION CLIENT权限

账号所需权限

grant REPLICATION CLIENT,REPLICATION SLAVE on *.* to my2sql@'%' identified by '9WJKXw8e';

grant select on dhr_organization_service.* TO my2sql@'%';

参数解析

参数

含义

-host string

mysql host, default 127.0.0.1 . (default "127.0.0.1")

实例IP

默认127.0.0.1

-port uint

mysql port, default 3306. (default 3306)

端口 默认3306

-server-id uint

this program replicates from mysql as slave to read binlogs. Must set this server id unique from other slaves, default 1113306 (default 1113306)

-user string

mysql user

用户

-password string

mysql user password.

用户密码

-databases string

only parse these databases, comma seperated, default all.

只解析这些数据库,逗号分隔,默认全部。

-tables string

only parse these tables, comma seperated, DONOT prefix with schema, default all.

只解析这些表,逗号分隔,不要以schema为前缀,默认全部。

-ignore-databases string

ignore parse these databases, comma seperated, default null

忽略解析的数据库,逗号分隔,默认为空

-ignore-tables string

ignore parse these tables, comma seperated, default null

忽略解析的表,逗号分隔,默认为空

-mysql-type string

valid options are: mysql,mariadb. server of binlog, mysql or mariadb, default mysql (default "mysql")

有效选项是:mysql,mariadb. server of binlog, mysql or mariadb,默认mysql(默认“mysql”)

-output-dir string

result output dir, default current work dir. Attension, result files could be large, set it to a dir with large free space

结果输出目录,默认当前工作目录。 注意,结果文件可能很大,将其设置为可用空间大的目录

-output-toScreen

Just output to screen,do not write to file

只输出到屏幕,不写入文件

-mode string

valid options are: repl,file. repl: as a slave to get binlogs from master. file: get binlogs from local filesystem. default repl (default "repl")

有效选项是:repl,file。 repl:作为从获取二进制日志。 文件:从本地文件系统获取二进制日志。 默认repl(默认“repl”)

-sql string

valid options are: insert,update,delete. only parse these types of sql, comma seperated, valid types are: insert, update, delete; default is all(insert,update,delete)

-start-datetime string

Start reading the binlog at first event having a datetime equal or posterior to the argument, it should be like this: "2020-01-01 01:00:00"

-stop-datetime string

Stop reading the binlog at first event having a datetime equal or posterior to the argument, it should be like this: "2020-12-30 01:00:00"

-start-file string

binlog file to start reading

-stop-file string

binlog file to stop reading

-start-pos uint

start reading the binlog at position (default 4)

-stop-pos uint

Stop reading the binlog at position (default 4)

-threads uint

Works with -workType=2sql|rollback. threads to run (default 2)

与 -workType=2sql|rollback 一起使用。 要运行的线程(默认 2)

-work-type string

valid options are: 2sql,rollback,stats. 2sql: convert binlog to sqls, rollback: generate rollback sqls, stats: analyze transactions. default: 2sql (default "2sql")

有效选项是:2sql,rollback,stats。 2sql:将binlog转换为sqls,rollback:生成回滚sqls,stats:分析事务。 默认值:2sql(默认“2sql”)

-tl string

time location to parse timestamp/datetime column in binlog, such as Asia/Shanghai. default Local (default "Local")

解析binlog中timestamp/datetime列的时区,如Asia/Shanghai。 默认本地(默认“本地”)

-print-interval int

works with -w='stats', print stats info each PrintInterval. Valid values range from 1 to 600, default 30 (default 30)

与 -w='stats' 一起使用,打印每个 PrintInterval 的统计信息。 有效值范围从 1 到 600,默认 30(默认 30)

-U

prefer to use unique key instead of primary key to build where condition for delete/update sql

优先使用唯一键而不是主键来构建删除/更新 sql 的 where 条件

-add-extraInfo

Works with -work-type=2sql|rollback. Print database/table/datetime/binlogposition...info on the line before sql, default false

与 -work-type=2sql|rollback 一起使用。 在sql前一行打印database/table/datetime/binlogposition...i等信息,默认false

-big-trx-row-limit int

受影响的行大于或等于此值的事务被视为大事务。 有效值范围从 1 到 10,默认 30000(默认 30000)

-do-not-add-prifixDb

Prefix table name witch database name in sql,ex: insert into db1.tb1 (x1, x1) values (y1, y1).

为表名添加库名

-file-per-table

One file for one table if true, else one file for all tables. default false. Attention, always one file for one binlog

如果为 true,则为一个表一个文件,否则为所有表一个文件。 默认false。 注意,一个binlog总是一个文件

-full-columns

For update sql, include unchanged columns. for update and delete, use all columns to build where condition.

default false, this is, use changed columns to build set part, use primary/unique key to build where condition

对于更新 sql,包括未更改的列。 对于更新和删除,使用所有列来构建 where 条件。

默认 false,即使用更改的列来构建集合部分,使用主键/唯一键来构建 where 条件

-ignore-primaryKey-forInsert

for insert statement when -workType=2sql, ignore primary key

对于 -workType=2sql 时的插入语句,忽略主键

-local-binlog-file string

local binlog files to process, It works with -mode=file

要处理的本地 binlog 文件,它与 -mode=file 一起使用

-long-trx-seconds int

transaction with duration greater or equal to this value is considerated as long transaction. Valid values range from 0 to 1, default 3600 (default 3600)

持续时间大于或等于该值的事务被看做长事务。 有效值范围从 0 到 1,默认 3600(默认 3600)

场景

创建账号 (最小权限 )

SELECT, REPLICATION SLAVE, REPLICATION CLIENTgrant SELECT, REPLICATION SLAVE, REPLICATION CLIENT on *.* to my2sql identified by 'my2sql';

场景1 回滚

CREATE TABLE `student` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`number` int(11) NOT NULL,

`name` varchar(255) DEFAULT NULL,

`add_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加的时间',

`content` json DEFAULT NULL,

PRIMARY KEY (`id`),

UNIQUE KEY `idx_name` (`number`,`name`)

) ENGINE=InnoDB AUTO_INCREMENT=1234 DEFAULT CHARSET=utf8

INSERT INTO `my2sql_test`.`student` (`id`,`number`,`name`,`add_time`,`content`) VALUES (1233,26,'ranran','2020-07-15 19:06:03',null);

INSERT INTO `my2sql_test`.`student` (`id`,`number`,`name`,`add_time`,`content`) VALUES (1232,134,'asdf','2020-07-12 11:08:41',null);

INSERT INTO `my2sql_test`.`student` (`id`,`number`,`name`,`add_time`,`content`) VALUES (1231,21,'chenxi','2020-07-12 10:12:45',null);

INSERT INTO `my2sql_test`.`student` (`id`,`number`,`name`,`add_time`,`content`) VALUES (1229,20,'chenxi','2020-07-11 16:20:50',null);

INSERT INTO `my2sql_test`.`student` (`id`,`number`,`name`,`add_time`,`content`) VALUES (1227,18,'hanran','2020-07-06 21:55:48','{\"age\":13,\"author\":\"liuhan\"}');

delete from student;

my2sql -user my2sql -password  -port 3307 \

-host 127.0.0.1  -databases my2sql_test -tables student \

-work-type rollback -start-file mysql-bin.000326 -add-extraInfo -sql delete \

-start-datetime "2022-07-08 10:30:00" --stop-datetime "2022-07-08 10:35:00" \

-output-dir /home/backups/my2sql

场景2 生成正向SQL

my2sql -host 127.0.0.1 -user my2sql -password  -port 3307 \

-databases my2sql_test -tables student \

-work-type 2sql -start-file mysql-bin.000326 -add-extraInfo -sql delete \

-start-datetime "2022-07-08 10:30:00" --stop-datetime "2022-07-08 10:35:00" \

-output-dir /home/backups/my2sql

场景3 DML与事务统计

my2sql -user my2sql -password  -port 3307 \

-host 127.0.0.1 \

-work-type stats -start-file mysql-bin.000325 stop-file mysql-bin.000325 \

-big-trx-row-limit 5 -long-trx-seconds 3 \

-output-dir /home/backups/my2sql

场景4 解析本地

需要连接数据库 server

my2sql -user my2sql -password  -port 3307 \

-host 127.0.0.1  -databases objective_stage_20220707 -tables objective \

-work-type 2sql -start-file mysql-bin.000326 -add-extraInfo -sql delete \

-start-datetime "2022-07-07 17:30:00" --stop-datetime "2022-07-07 17:35:00" \

-output-dir /home/backups/

与binlog2sql性能对比

1.2G binlog

my2sql

binlog2sql

正向本地

2线程

89秒

8线程

72秒

16线程

77秒

正向SQL

8线程

62秒

回滚SQL

8线程

35秒

2601 秒

参考

GitHub - liuhr/my2sql

相关文章:

【MySQL工具】my2sql-快速解析binlog

​​​​​​ 目录 ​​​​​​ 安装 my2sql简介 用途 工具优势 限制 账号所需权限 参数解析 场景 场景1 回滚 场景2 生成正向SQL 场景3 DML与事务统计 场景4 解析本地 与binlog2sql性能对比 安装 安装比较简单 直接下载二进制命令即可使用 wget https://git…...

vueRouter常用属性

vueRouter常用属性 basemodehashhistoryhistory模式下可能会遇到的问题及解决方案 routesprops配置(最佳方案) scrollBehavior base 基本的路由请求的路径 如果整个单页应用服务在 /app/ 下,然后 base 就应该设为 “/app/”,所有的请求都会在url之后加上/app/ new …...

Qt5.15.2的镜像网址

其它版本的qt把相应数字更换即可 已安装的QT怎么更新安装组件。离线版QT安装:已安装的QT怎么更新安装组件。离线版QT安装_哔哩哔哩_bilibili https://mirrors.tuna.tsinghua.edu.cn/qt/online/qtsdkrepository/windows_x86/desktop/qt5_5152_wasm/https://mirrors.…...

Python隐藏特性:字符串驻留、常量折叠

下面是Python字符串的一些微妙的特性,绝对会让你大吃一惊。 案例一: a “some_string” id(a) 140420665652016 id(“some” “_” “string”) # 注意两个的id值是相同的. 140420665652016 案例二: a “wtf” b “wtf” a is b True …...

2-Python与设计模式--工厂类相关模式

23种计模式之 前言 (5)单例模式、工厂模式、简单工厂模式、抽象工厂模式、建造者模式、原型模式、(7)代理模式、装饰器模式、适配器模式、门面模式、组合模式、享元模式、桥梁模式、(11)策略模式、责任链模式、命令模式、中介者模…...

PGP 遇上比特币

重复使用 PGP 密钥作为比特币密钥 介绍 在数字安全领域,密码学在确保数据的完整性和真实性方面发挥着至关重要的作用。 一种广泛使用的加密技术是使用 Pretty Good Privacy (PGP1)。 PGP 为安全通信(例如电子邮件、文件传输和数据存储)提供加…...

项目demo —— GPT 聊天机器人

本文介绍我的开源项目 TelegramChatBot,这是一个基于 OpenAI GPT API 开发的 telegram 机器人,具有多模态交互能力,求 star!感谢大家!在 telegram jokerController_bot 立即体验!欢迎对 GPT 应用开发或对 t…...

Airtest进阶使用篇!提高脚本稳定性 + 批量运行脚本!

一、背景 今天彭于晏为大家分享Airtest进阶使用篇,主要包含两块的内容: 提高脚本稳定性批量运行脚本生成测试报告 二、提高脚本稳定性 1、添加全局配置: #全局设置 ST.FIND_TIMEOUT10 #设置隐式等待时长,默认识别图片时间是30秒,可改为…...

数据库系统概述之数据库优化

为什么需要进行优化? 数据库性能瓶颈 数据库服务器的性能受许多因素影响,包括硬件能力、系统规模、业务模型及架构、代码设计、数据库表设计、系统环境等。 因此,可以从几个方面进行数据库优化 喜欢点赞收藏,如有疑问&#xff…...

【error:Custom elements in iteration require ‘v-bind:key‘ directives】元素绑定:key

在vue3中使用v-for操作的时候&#xff0c;报error Custom elements in iteration require v-bind:key directives 当我想自定义绘制echarts图的代码&#xff1a; <el-row><div v-if"data.chartDataList.length > 0"><el-col :span"12&quo…...

TA-Lib学习研究笔记(二)——Overlap Studies下

TA-Lib学习研究笔记&#xff08;二&#xff09;——Overlap Studies下 &#xff08;11&#xff09;SAR - Parabolic SAR 抛物线指标 函数名&#xff1a;SAR 名称&#xff1a; 抛物线指标 简介&#xff1a;抛物线转向也称停损点转向&#xff0c;是利用抛物线方式&#xff0c;随…...

三.排序与分页

目录 一.排序数据二.分页 一.排序数据 1.排序规则 使用ORDER BY 子句排序 ASC&#xff08;ascend&#xff09;升序DESC&#xff08;descend&#xff09;降序 ORDER BY 子句在SELECT语句的结尾 2.单列排序 SELECT last_name, job_id, department_id, hire_date FROM e…...

第一个php扩展开发的demo

cd /root/soft/php/php-5.2.6/ext ./ext_skel --extnameheiyeluren cd /root/soft/php/php-5.2.6/ext/heiyeluren vi config.m4 打开文件后去掉 dnl &#xff0c;获得下面的信息&#xff1a; PHP_ARG_ENABLE(rot13, whether to enable heiyeluren support, [ --enable-heiyelu…...

A stop job is running for Session c1 of user root (25s 1min 30s)问题

写在前面 今天在前端点击重启按钮&#xff0c;突然发现开发板的串口打印信息卡住了&#xff0c;时间比较长的有一处&#xff0c;比较短的有两处&#xff0c;大致为A stop job is running for Session c1 of user root (25s 1min 30s)&#xff0c;此处估计是在关机重启的时候&a…...

C语言进阶之笔试题详解(2)

前言 这里的内容包括二维数组笔试题和指针笔试题&#xff0c;供给读者对这部分知识进行加深和巩固。 ✨ 猪巴戒&#xff1a;个人主页✨ 所属专栏&#xff1a;《C语言进阶》 &#x1f388;跟着猪巴戒&#xff0c;一起学习C语言&#x1f388; 目录 前言 笔试题 二维数组 题目…...

【开源】基于Vue和SpringBoot的独居老人物资配送系统

项目编号&#xff1a; S 045 &#xff0c;文末获取源码。 \color{red}{项目编号&#xff1a;S045&#xff0c;文末获取源码。} 项目编号&#xff1a;S045&#xff0c;文末获取源码。 目录 一、摘要1.1 项目介绍1.2 项目录屏 二、功能模块三、系统展示四、核心代码4.1 查询社区4…...

Linux常用命令----cp 命令

文章目录 1. 基本用法2. 保留文件属性3. 递归复制4. 仅复制更新的文件5. 交互式复制6. 创建符号链接而非复制7. 复制并备份目标文件8. 指定备份后缀9. 详细输出总结 Linux操作系统中&#xff0c;cp 命令是一个非常基础且强大的工具&#xff0c;用于复制文件或目录。本文将详细介…...

前端:HTML鼠标样式及其对应的CSS属性值

1、默认箭头样式&#xff1a; selector {cursor: default; } 2、手型样式 selector {cursor: pointer; } 3、文本选择样式&#xff1a; selector {cursor: text; } 4、移动手型样式&#xff1a; selector {cursor: move; } 5、缩放手型样式&#xff1a; selector {cur…...

Linux 命令chgrp chown chmod

chgrp chown chmod 介绍 chgrp : 修改文件所属用户组 chown : 修改文件拥有者 chmod : 修改文件权限1 chgrp 命令功能: chgrp命令用来改变文件或目录所属的用户组。该命令用来改变指定文件所属的用户组。其中&#xff0c;组名可以是用户组的id&#xff0c;也可以是用户组的组…...

网络篇---第七篇

系列文章目录 文章目录 系列文章目录前言一、什么是长连接和短连接?二、长连接和短连接的优缺点?三、说说长连接短连接的操作过程前言 前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到网站,这篇文章男女通用,看懂了就去分…...

工业安全零事故的智能守护者:一体化AI智能安防平台

前言&#xff1a; 通过AI视觉技术&#xff0c;为船厂提供全面的安全监控解决方案&#xff0c;涵盖交通违规检测、起重机轨道安全、非法入侵检测、盗窃防范、安全规范执行监控等多个方面&#xff0c;能够实现对应负责人反馈机制&#xff0c;并最终实现数据的统计报表。提升船厂…...

跨链模式:多链互操作架构与性能扩展方案

跨链模式&#xff1a;多链互操作架构与性能扩展方案 ——构建下一代区块链互联网的技术基石 一、跨链架构的核心范式演进 1. 分层协议栈&#xff1a;模块化解耦设计 现代跨链系统采用分层协议栈实现灵活扩展&#xff08;H2Cross架构&#xff09;&#xff1a; 适配层&#xf…...

现代密码学 | 椭圆曲线密码学—附py代码

Elliptic Curve Cryptography 椭圆曲线密码学&#xff08;ECC&#xff09;是一种基于有限域上椭圆曲线数学特性的公钥加密技术。其核心原理涉及椭圆曲线的代数性质、离散对数问题以及有限域上的运算。 椭圆曲线密码学是多种数字签名算法的基础&#xff0c;例如椭圆曲线数字签…...

涂鸦T5AI手搓语音、emoji、otto机器人从入门到实战

“&#x1f916;手搓TuyaAI语音指令 &#x1f60d;秒变表情包大师&#xff0c;让萌系Otto机器人&#x1f525;玩出智能新花样&#xff01;开整&#xff01;” &#x1f916; Otto机器人 → 直接点明主体 手搓TuyaAI语音 → 强调 自主编程/自定义 语音控制&#xff08;TuyaAI…...

06 Deep learning神经网络编程基础 激活函数 --吴恩达

深度学习激活函数详解 一、核心作用 引入非线性:使神经网络可学习复杂模式控制输出范围:如Sigmoid将输出限制在(0,1)梯度传递:影响反向传播的稳定性二、常见类型及数学表达 Sigmoid σ ( x ) = 1 1 +...

OpenLayers 分屏对比(地图联动)

注&#xff1a;当前使用的是 ol 5.3.0 版本&#xff0c;天地图使用的key请到天地图官网申请&#xff0c;并替换为自己的key 地图分屏对比在WebGIS开发中是很常见的功能&#xff0c;和卷帘图层不一样的是&#xff0c;分屏对比是在各个地图中添加相同或者不同的图层进行对比查看。…...

【JavaWeb】Docker项目部署

引言 之前学习了Linux操作系统的常见命令&#xff0c;在Linux上安装软件&#xff0c;以及如何在Linux上部署一个单体项目&#xff0c;大多数同学都会有相同的感受&#xff0c;那就是麻烦。 核心体现在三点&#xff1a; 命令太多了&#xff0c;记不住 软件安装包名字复杂&…...

push [特殊字符] present

push &#x1f19a; present 前言present和dismiss特点代码演示 push和pop特点代码演示 前言 在 iOS 开发中&#xff0c;push 和 present 是两种不同的视图控制器切换方式&#xff0c;它们有着显著的区别。 present和dismiss 特点 在当前控制器上方新建视图层级需要手动调用…...

腾讯云V3签名

想要接入腾讯云的Api&#xff0c;必然先按其文档计算出所要求的签名。 之前也调用过腾讯云的接口&#xff0c;但总是卡在签名这一步&#xff0c;最后放弃选择SDK&#xff0c;这次终于自己代码实现。 可能腾讯云翻新了接口文档&#xff0c;现在阅读起来&#xff0c;清晰了很多&…...

PostgreSQL——环境搭建

一、Linux # 安装 PostgreSQL 15 仓库 sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-$(rpm -E %{rhel})-x86_64/pgdg-redhat-repo-latest.noarch.rpm# 安装之前先确认是否已经存在PostgreSQL rpm -qa | grep postgres# 如果存在&#xff0…...