欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

利用MyFlash實現(xiàn)MySQL數(shù)據(jù)閃回的操作指南

 更新時間:2024年06月21日 09:08:58   作者:逢生博客  
MySQL數(shù)據(jù)閃回是一種高級功能,它允許你在數(shù)據(jù)庫中恢復(fù)到某個特定的時間點,通常是事務(wù)開始或保存點的狀態(tài),以便處理數(shù)據(jù)錯誤或回滾意外更改,本文給大家介紹了如何利用MyFlash實現(xiàn)MySQL數(shù)據(jù)閃回,需要的朋友可以參考下

Github

MyFlash 限制

僅支持 5.6 與 5.7

binlog 格式必須為 row,且 binlog_row_image=full

只能回滾DML(增、刪、改

MySQL 準(zhǔn)備

注: 本章 MySQL 是采用 Docker 部署,容器內(nèi)是 不帶mysqlbinlog 的,可以從已安裝 MySQL 的Linux服務(wù)器上拷貝 mysqlbinlog 文件。

開啟 binlog

[mysqld]
# binlog功能
log_bin=/var/lib/mysql/mysql-bin
# binlog 文件格式
binlog_format=ROW
binlog_row_image=FULL
# binlog 文件保留時間7天(默認(rèn)0天)
expire_logs_days=7
# binlog 單個文件的最大值大小(默認(rèn)1G)
max_binlog_size=512m
# 開啟 binlog 后需要創(chuàng)建 function 或 procedure 時要開啟
log_bin_trust_function_creators=1
# 服務(wù)id,以區(qū)分主庫和備庫
server-id=1
-- 顯示是否開啟 binlog
show variables like 'log_bin%';
-- 顯示 binlog 文件格式
show variables like 'binlog_format%';
-- 顯示 binlog 文件保留時間
show variables like 'expire_logs_days%';
-- 顯示 binlog 單個文件的最大值大小
show variables like 'max_binlog_size%';
-- 顯示 binlog 事件
show binlog events;
-- 顯示全部 binlog 文件列表
show binary logs;
show master logs;
-- 顯示最新 binlog 文件編號以及最后一個操作事件結(jié)束點(Position)值
show master status;
-- 結(jié)束當(dāng)前 binlog 文件并生成新的 binlog 文件
flush logs;
-- 重置 binlog 文件(清空全部 biglog 文件)
reset master;

注: binlog 默認(rèn)存放在 /var/lib/mysql/ 數(shù)據(jù)庫文件目錄。

mysqlbinlog

  • 查看 Linux 環(huán)境下 mysqlbinlog 目錄
# /usr/bin/mysqlbinlog
whereis mysqlbinlog
  • 將 mysqlbinlog 文件復(fù)制到容器內(nèi)的 /usr/bin 目錄
docker cp mysqlbinlog mysql:/usr/bin
# 進(jìn)入容器內(nèi)
docker exec -it mysql /bin/bash
# 在容器內(nèi)為 mysqlbinlog 添加權(quán)限
chmod +x /usr/bin/mysqlbinlog
  • 使用 mysqlbinlog 生成 sql 文件
# 進(jìn)入容器內(nèi)執(zhí)行
mysqlbinlog --no-defaults --base64-output=DECODE-ROWS -v /var/lib/mysql/mysql-bin.000001 >/tmp/binlog-000001.sql
# 進(jìn)入容器內(nèi)執(zhí)行
mysqlbinlog --no-defaults \
--database=db_name \
--start-datetime='2024-06-20 00:00:00' \
--stop-datetime='2024-06-20 17:00:00' \
/var/lib/mysql/mysql-bin.000001 >/tmp/binlog-000001.sql

安裝 MyFlash

  • 安裝依賴
# 安裝 gcc glib-2.0
yum install -y gcc libgnomeui-devel
# 驗證是否安裝成功
pkg-config --modversion glib-2.0
  • 安裝MyFlash
# 下載源碼
git clone https://github.com/Meituan-Dianping/MyFlash.git
cd MyFlash
# 動態(tài)編譯鏈接安裝
gcc -w `pkg-config --cflags --libs glib-2.0` source/binlogParseGlib.c -o binary/flashback
  • 配置環(huán)境變量
vim /etc/profile
# 在文件末尾添加
alias flashback=~/MyFlash/binary/flashback
source /etc/profile
  • 驗證是否安裝成功
cd ~/MyFlash/binary
./flashback --help

flashback 選項

選項說明
–databaseNamesdatabaseName to apply. if multiple, seperate by comma(,)
–tableNamestableName to apply. if multiple, seperate by comma(,)
–tableNames-filetableName to apply. if multiple, seperate by comma(,)
–start-positionstart position
–stop-positionstop position
–start-datetimestart time (format %Y-%m-%d %H:%M:%S)
–stop-datetimestop time (format %Y-%m-%d %H:%M:%S)
–sqlTypessql type to filter . support INSERT, UPDATE ,DELETE. if multiple, seperate by comma(,)
–maxSplitSizemax file size after split, the uint is M
–binlogFileNamesbinlog files to process. if multiple, seperate by comma(,)
–outBinlogFileNameBaseoutput binlog file name base
–logLevellog level, available option is debug,warning,error
–include-gtidsgtids to process. if multiple, seperate by comma(,)
–include-gtids-filegtids to process. if multiple, seperate by comma(,)
–exclude-gtidsgtids to skip. if multiple, seperate by comma(,)
–exclude-gtids-filegtids to skip. if multiple, seperate by comma(,)

生成回滾文件

# 進(jìn)入MyFlash的bin目錄
cd ~/MyFlash/binary
# 生成回滾文件,執(zhí)行后會在當(dāng)前目錄下生成 binlog_output_base.flashback 文件
./flashback --sqlTypes='INSERT' \
--binlogFileNames=/var/lib/mysql/mysql-bin.000001 \
--databaseNames=db_name \
--tableNames=table_name \
--start-datetime='2024-06-20 18:23:00'

執(zhí)行回滾操作

# 在binlog_output_base.flashback所在目錄下執(zhí)行以下命令
mysqlbinlog binlog_output_base.flashback | mysql -h 127.0.0.1 -uroot -p
# 或
mysqlbinlog binlog_output_base.flashback | mysql -uroot -p
# 輸入數(shù)據(jù)庫密碼

到此這篇關(guān)于利用MyFlash實現(xiàn)MySQL數(shù)據(jù)閃回的操作指南的文章就介紹到這了,更多相關(guān)MyFlash MySQL數(shù)據(jù)閃回內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • MySQL索引總結(jié)(Index?Type)

    MySQL索引總結(jié)(Index?Type)

    本文主要介紹了MySQL索引總結(jié)(Index?Type),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-02-02
  • MYSQL 刪除一個字段前判斷字段是否存在的辦法

    MYSQL 刪除一個字段前判斷字段是否存在的辦法

    這篇文章主要介紹了MYSQL 刪除一個字段前判斷字段是否存在的辦法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2024-08-08
  • MySQL中的回表和索引覆蓋示例詳解

    MySQL中的回表和索引覆蓋示例詳解

    索引覆蓋是一種避免回表查詢的優(yōu)化策略,具體的做法就是將要查詢的數(shù)據(jù)作為索引列建立普通索,下面這篇文章主要給大家介紹了關(guān)于MySQL中回表和索引覆蓋的相關(guān)資料,需要的朋友可以參考下
    2021-09-09
  • 解析數(shù)據(jù)庫分頁的兩種方法對比(row_number()over()和top的對比)

    解析數(shù)據(jù)庫分頁的兩種方法對比(row_number()over()和top的對比)

    本篇文章是對數(shù)據(jù)庫分頁的兩種方法對比(row_number()over()和top的對比)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-07-07
  • 詳細(xì)聊一聊mysql的樹形結(jié)構(gòu)存儲以及查詢

    詳細(xì)聊一聊mysql的樹形結(jié)構(gòu)存儲以及查詢

    由于mysql是關(guān)系型數(shù)據(jù)庫,因此對于類似組織架構(gòu),子任務(wù)等相關(guān)的樹形結(jié)構(gòu)的處理不是很友好,下面這篇文章主要給大家介紹了關(guān)于mysql樹形結(jié)構(gòu)存儲以及查詢的相關(guān)資料,需要的朋友可以參考下
    2022-04-04
  • mysql數(shù)據(jù)庫查詢基礎(chǔ)命令詳解

    mysql數(shù)據(jù)庫查詢基礎(chǔ)命令詳解

    這篇文章主要介紹了mysql數(shù)據(jù)庫查詢基礎(chǔ)命令,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-11-11
  • Django連接本地mysql數(shù)據(jù)庫(pycharm)的步驟

    Django連接本地mysql數(shù)據(jù)庫(pycharm)的步驟

    這篇文章主要介紹了Django連接本地mysql數(shù)據(jù)庫(pycharm)的步驟,本文分步驟給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-09-09
  • 詳解MySQL事務(wù)的ACID如何實現(xiàn)

    詳解MySQL事務(wù)的ACID如何實現(xiàn)

    事務(wù)(Transaction)是并發(fā)控制的基本單位,所謂的事務(wù)呢,它是一個操作序列,這些操作要么都執(zhí)行,要么都不執(zhí)行,它是一個不可分割的工作單位,本文給大家詳細(xì)介紹了MySQL事務(wù)的ACID如何實現(xiàn),需要的朋友可以參考下
    2023-10-10
  • mysql提示Can't?connect?to?MySQL?server?on?localhost?(10061)完美解決方法

    mysql提示Can't?connect?to?MySQL?server?on?localhost

    這篇文章主要介紹了Can't?connect?to?MySQL?server?on?localhost?(10061)解決方法,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-03-03
  • mysql數(shù)據(jù)庫備份及恢復(fù)命令 mysqldump,source的用法

    mysql數(shù)據(jù)庫備份及恢復(fù)命令 mysqldump,source的用法

    mysql數(shù)據(jù)庫備份及恢復(fù)命令 mysqldump,source的用法,需要的朋友可以參考下。
    2011-02-02

最新評論