MySQL數據閃回工具my2sql的使用

場景:
當你或者其它人員誤操作數據庫不小心刪除或者更新了一批數據,但是是當時又沒事先備份時,你可以 用這個 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…