场景:
当你或者其它人员误操作数据库不小心删除或者更新了一批数据,但是是当时又没事先备份时,你可以 用这个 my2sql工具快速帮你找回数据。就是如此的丝滑。但是要注意的是只限于dml语句,所以我们在操作数据库前必需先备份哦,备份!备份!备份! 重要的事说三遍。

工具名称:my2sql #my2sql是用go语言写的。
#N年前我用过Binlog2SQL,它需要安装依赖包,有点麻烦,binlog2sql是用python写的。

工具github地址:
https://github.com/liuhr/my2sql

一, 解析出原始执行的语句

/data/my2sql-master/releases/centOS_release_7.x/my2sql -user xxxxx -password xxxx -host xx.xx.xx.xx -mode repl -work-type 2sql -start-file mysql-bin.000974 -start-datetime “2021-12-08 13:25:21” -stop-datetime “2021-12-08 14:54:53” -output-dir ./tmpdir

二, 生成回滚sql

1) delete测试
root@xx.xx.xx.xx:3306 17:38: [test]>delete from api_account where id = 1001;
Query OK, 1 row affected (0.01 sec)

root@xx.xx.xx.xx:3306 17:38: [test]>select now();
±--------------------+
| now() |
±--------------------+
| 2021-12-09 17:39:08 |
±--------------------+
1 row in set (0.00 sec)

root@xx.xx.xx.xx:3306 17:39: [test]>select * from api_account where id = 1001;
Empty set (0.00 sec)

/data/my2sql-master/releases/centOS_release_7.x/my2sql -user yl_xxxx -password xxxxxx -host x -mode repl -work-type rollback -start-file mysql-bin.000230 -start-datetime “2021-12-09 17:38:00” -stop-datetime “2021-12-09 17:42:00” -output-dir ./tmpdir

cat tmpdir/rollback.230.sql
INSERT INTO test.api_account (id,lmdm_customer_id,lmdm_customer_code,private_key,full_name,short_name,mobile,forbidden,create_time,remark) VALUES (1001,1,‘J0086000417’,‘c7895f3579804a93aff8e5c977004da9’,‘多多打单’,‘D15’,‘13537867075’,1,‘2020-02-14 13:24:30’,null);

  1. update测试

root@xx.xx.xx.xx:3306 17:48: [test]>select * from api_account where id = 1001;
±-----±-----------------±-------------------±---------------------------------±-------------±-----------±------------±----------±--------------------±-------+
| id | lmdm_customer_id | lmdm_customer_code | private_key | full_name | short_name | mobile | forbidden | create_time | remark |
±-----±-----------------±-------------------±---------------------------------±-------------±-----------±------------±----------±--------------------±-------+
| 1001 | 1 | J0086000417 | c7895f3579804a93aff8e5c977004da9 | xx打单 | D15 | 13537867075 | 1 | 2020-02-14 13:24:30 | NULL |
±-----±-----------------±-------------------±---------------------------------±-------------±-----------±------------±----------±--------------------±-------+
1 row in set (0.00 sec)

root@xx.xx.xx.xx:3306 17:48: [test]>update api_account set lmdm_customer_code=‘J0086000419’ where id = 1001;select now();
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

±--------------------+
| now() |
±--------------------+
| 2021-12-09 17:50:00 |
±--------------------+
1 row in set (0.00 sec)

root@xx.xx.xx.xx:3306 17:50: [test]>select * from api_account where id = 1001;
±-----±-----------------±-------------------±---------------------------------±-------------±-----------±------------±----------±--------------------±-------+
| id | lmdm_customer_id | lmdm_customer_code | private_key | full_name | short_name | mobile | forbidden | create_time | remark |
±-----±-----------------±-------------------±---------------------------------±-------------±-----------±------------±----------±--------------------±-------+
| 1001 | 1 | J0086000419 | c7895f3579804a93aff8e5c977004da9 | 多多打单 | D15 | 13537867075 | 1 | 2020-02-14 13:24:30 | NULL |
±-----±-----------------±-------------------±---------------------------------±-------------±-----------±------------±----------±--------------------±-------+
1 row in set (0.00 sec)

[root@sharding-9-150 1]# /data/my2sql-master/releases/centOS_release_7.x/my2sql -user xxxxx -password xxxxxx -host xx.xx.xx.xx -mode repl -work-type rollback -start-file mysql-bin.000230 -start-datetime “2021-12-09 17:49:00” -stop-datetime “2021-12-09 17:51:00” -output-dir ./tmpdir

[2021/12/09 17:51:12] [info] events.go:210 start thread to write redo/rollback sql into file
[2021/12/09 17:51:12] [info] binlogsyncer.go:360 begin to sync binlog from position (mysql-bin.000230, 4)
[2021/12/09 17:51:12] [info] events.go:60 start thread 1 to generate redo/rollback sql
[2021/12/09 17:51:12] [info] events.go:60 start thread 2 to generate redo/rollback sql
[2021/12/09 17:51:12] [info] stats_process.go:166 start thread to analyze statistics from binlog
[2021/12/09 17:51:12] [info] repl.go:16 start to get binlog from mysql
[2021/12/09 17:51:12] [info] binlogsyncer.go:777 rotate to (mysql-bin.000230, 4)
[2021/12/09 17:51:16] [info] events.go:244 finish processing mysql-bin.000230 183072284
[2021/12/09 17:51:16] [info] com.go:71 stop to get event. StopDateTime set. current event Timestamp 1639043462 Stop DateTime Timestamp 1639043460
[2021/12/09 17:51:16] [info] repl.go:18 finish getting binlog from mysql
[2021/12/09 17:51:16] [info] stats_process.go:266 exit thread to analyze statistics from binlog
[2021/12/09 17:51:16] [info] events.go:185 exit thread 2 to generate redo/rollback sql
[2021/12/09 17:51:16] [info] events.go:185 exit thread 1 to generate redo/rollback sql
[2021/12/09 17:51:16] [info] events.go:259 finish writing rollback sql into tmp files, start to revert content order of tmp files
[2021/12/09 17:51:16] [info] rollback_process.go:15 start thread 1 to revert rollback sql files
[2021/12/09 17:51:16] [info] rollback_process.go:41 start to revert tmp file tmpdir/.rollback.230.sql into tmpdir/rollback.230.sql
[2021/12/09 17:51:16] [info] rollback_process.go:156 finish reverting tmp file tmpdir/.rollback.230.sql into tmpdir/rollback.230.sql
[2021/12/09 17:51:16] [info] rollback_process.go:25 exit thread 1 to revert rollback sql files
[2021/12/09 17:51:16] [info] events.go:272 finish reverting content order of tmp files
[2021/12/09 17:51:16] [info] events.go:277 exit thread to write redo/rollback sql into file

[root@sharding-9-150 1]# ls tmpdir/
biglong_trx.txt binlog_status.txt rollback.230.sql
[root@sharding-9-150 1]# cat tmpdir/rollback.230.sql
UPDATE test.api_account SET lmdm_customer_code=‘J0086000417’ WHERE id=1001;

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/news/917256.shtml
繁体地址,请注明出处:http://hk.pswp.cn/news/917256.shtml
英文地址,请注明出处:http://en.pswp.cn/news/917256.shtml

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

9.1无法恢复的错误与 panic!

无法恢复的错误与 panic! 有时你的代码中会发生严重问题,而你无能为力。在这些情况下,Rust 提供了 panic! 宏。实际上,有两种方式会导致 panic:一种是执行某个操作使代码产生 panic(例如访问数组越界)&…

分享低功耗单火线开关语音识别方案

在众多老旧建筑和常规家居环境里,单火线布线是主流方式。单火线语音识别芯片方案通过研发和应用特殊的单火线语音识别芯片,实现设备在单火线供电条件下稳定运行,并精准识别语音指令,为智能家居、智能照明等领域带来便捷的语音控制…

如何在Windows操作系统上通过conda 安装 MDAnalysis

MDAnalysis 是一个开源的 Python 库,旨在提供一个高效且灵活的方式来分析和处理分子动力学(MD)模拟数据。它可以从不同的文件格式中读取模拟轨迹和结构数据,进行复杂的数据处理和分析,广泛应用于生物物理学、化学、材料科学等领域。 一、创建虚拟环境 为了能够顺利安装,减…

实用PDF演示解决方案

它打破了传统阅 读模式,让PDF文档也能像PPT一样流畅播放,特别适合汇报、讲解等展示场景。它是绿色单文件版,无需安装,双击红色图标即点即用。运行后第一件事,建议把界面语言切换成中文,操作更顺手。导入PDF…

VS Code中如何关闭Github Copilot

点击顶部搜索栏后面的Copilot图标,在下拉菜单中选择Hide Copilot。在弹出的提示框中,点击Hide Copilot按钮就可以了。

MySQL学习从零开始--第六部分

Binlog是什么?有哪几种格式?推荐使用哪种,为什么 Binlog是什么 Binlog二进制日志是MySQL Server层记录所有更改数据库内容的操作日志的二进制文件,如操作UPDATE,DELETE,INSERTBinlog不记录SELECT,SHOW等查询操作使主从…

走进computed,了解computed的前世今生

computed(计算属性)并不是vue独创的,而是源自计算机科学和响应式编程的长期发展 计算理论的奠基: 函数式编程的纯函数思想:计算属性的核心特征(无副作用、依赖输入确定输出)直接来源于函数式编程…

Java 23 新特性解析与代码示例

Java 23 新特性解析与代码示例 文章目录Java 23 新特性解析与代码示例1. 引言2. 正式特性2.1. Markdown文档注释 (JEP 467)2.2. 废弃sun.misc.Unsafe的内存访问方法以移除 (JEP 471)2.3. ZGC:默认启用代际模式 (JEP 474)3. 预览特性3.1. 原始类型在模式、instanceof…

spring boot + mybatis + mysql 只有一个实体类的demo

使用MyBatis进行数据库操作,配置简单。主要演示了mybatis可以不用只使用方法名来对应mapper.java和mapper.xml。 目录结构 pom.xml src/ ├── main/ │ ├── java/ │ │ └── com/ │ │ └── springbootjdbcweb/ │ │ └── …

iRemovalPro完美绕iCloud插卡打电话,A12+支持iOS 18.1.1

iRemovalPro 专业工具全解析与操作指南 (支持iOS 14.0 - 16.6.1,A7-A15芯片设备) 👉下载地址见文末 iRemoval Pro iRemoval 专业版是一款来自外国安全研究员的工具,用来帮助一些人因为忘记自己的ID或者密码&#xff0c…

安卓SELinux策略语法

目录前言一、 通用AV规则语法1.1 allow source target:class permissions;1.2 neverallow source target:class permissions;二、type三、attribute四、typeattribute五、alias六、typealias七、init_daemon_domain7.1 init_daemon_domain 宏概述7.2 宏展开与实现7.2.1 展开后规…

vscode cursor配置php的debug,docker里面debug

VSCode PHP调试配置指南 概述 本文介绍如何在VSCode中配置PHP调试环境,包括本地和Docker环境。 前置要求 VSCodePHP 7.0Xdebug扩展PHP Debug VSCode扩展 本地调试配置 1. 安装Xdebug # Ubuntu/Debian sudo apt-get install php-xdebug# MacOS brew install p…

elk部署加日志收集

清华大学镜像源地址:Index of /elasticstack/8.x/yum/8.13.2/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror 一、elasticsearch 1.安装 rpm -ivh elastic-agent-8.13.2-x86_64.rpm 2.修改配置 vim /etc/elasticsearch/elasticsearch.yml 修改如下&…

dify 升级1.7.1 插件无法下载依赖

dify 升级1.7.1 插件无法下载依赖 1. 安装通义千问插件,各种报错; 使用下面命令查看docker 镜像日志 docker logs -f --tail100 docker-plugin_daemon-1 2025/08/01 07:42:21 full_duplex.go:59: [INFO]init environment for plugin langgenius/tongyi…

linux中简易云盘系统项目实战:基于 TCP协议的 Socket 通信、json数据交换、MD5文件区别与多用户文件管理实现

📋 项目介绍 本项目是一个基于Linux环境的简易云盘系统,采用C/S(客户端/服务器)架构,实现了类似百度网盘的基本功能。系统通过TCP Socket进行网络通信,使用JSON格式进行数据交换,利用SQLite3数据…

linux中posix消息队列的使用记录

在linux中使用posix中的消息队列时遇到了一个问题,就是在发送消息时,如果队列满了,mq_send接口会一直阻塞,经过查找资料后才发现,该接口默认是阻塞的,也就是说,当队列满了以后,接口会…

01 基于sklearn的机械学习-机械学习的分类、sklearn的安装、sklearn数据集及数据集的划分、特征工程(特征提取与无量纲化、特征降维)

文章目录机械学习机械学习分类1. 监督学习2. 半监督学习3. 无监督学习4. 强化学习机械学习的项目开发步骤scikit-learn1 scikit-learn安装2 sklearn数据集1. sklearn 玩具数据集鸢尾花数据集糖尿病数据集葡萄酒数据集2. sklearn现实世界数据集20 新闻组数据集3. 数据集的划分特…

n8n】n8n的基础概念

以下是为初学者整理的 n8n 基本概念总结,帮助快速理解核心功能和使用逻辑:1. 工作流(Workflow)核心单元:n8n的一切操作基于工作流,代表一个自动化流程。组成:由多个节点(Nodes&#…

机器学习基础-matplotlib

一、相关知识点二、plotfrom pylab import mpl # 设置显示中文字体 mpl.rcParams["font.sans-serif"] ["SimHei"] # 设置正常显示符号 mpl.rcParams["axes.unicode_minus"] False #%%#%% import matplotlib.pyplot as plt import random# 画出…

spring-ai-alibaba 学习(十九)——graph之条件边、并行节点、子图节点

前面了解了基础的概念及流程,以及一些参数类下面了解一些特殊的边和节点条件边常见的流程图可能长这个样子:其中菱形的为条件节点(或者叫判定节点),但是在spring-ai-alibaba-graph中,并没有条件节点在sprin…