mysql5.7 闪回数据(update delete insert)
本次测试用Myflash闪回dml操作,有个前提条件是log_bin开启并且log模式是row;
mysql> show global variables like "binlog%";
+--------------------------------------------+--------------+
| Variable_name | Value |
+--------------------------------------------+--------------+
| binlog_cache_size | |
| binlog_checksum | NONE |
| binlog_direct_non_transactional_updates | OFF |
| binlog_error_action | ABORT_SERVER |
| binlog_format | ROW |
| binlog_group_commit_sync_delay | |
| binlog_group_commit_sync_no_delay_count | |
| binlog_gtid_simple_recovery | ON |
| binlog_max_flush_queue_time | |
| binlog_order_commits | ON |
| binlog_row_image | FULL |
| binlog_rows_query_log_events | OFF |
| binlog_stmt_cache_size | |
| binlog_transaction_dependency_history_size | |
| binlog_transaction_dependency_tracking | COMMIT_ORDER |
+--------------------------------------------+--------------+
rows in set (0.00 sec) mysql> show variables like 'log_%';
+----------------------------------------+-----------------------------+
| Variable_name | Value |
+----------------------------------------+-----------------------------+
| log_bin | ON |
| log_bin_basename | /data/mysql/mysql-bin |
| log_bin_index | /data/mysql/mysql-bin.index |
| log_bin_trust_function_creators | OFF |
| log_bin_use_v1_row_events | OFF |
| log_builtin_as_identified_by_password | OFF |
| log_error | /data/log/mysql-error.log |
| log_error_verbosity | |
| log_output | FILE |
| log_queries_not_using_indexes | OFF |
| log_slave_updates | ON |
| log_slow_admin_statements | OFF |
| log_slow_slave_statements | OFF |
| log_statements_unsafe_for_binlog | ON |
| log_syslog | OFF |
| log_syslog_facility | daemon |
| log_syslog_include_pid | ON |
| log_syslog_tag | |
| log_throttle_queries_not_using_indexes | |
| log_timestamps | UTC |
| log_warnings | |
+----------------------------------------+-----------------------------+
rows in set (0.00 sec)
安装myflash
git clone https://github.com/Meituan-Dianping/MyFlash.git
myflash依赖glibc查询
[root@redis01 MyFlash]# rpm -qa|grep glibc
glibc-headers-2.12-1.209.0.1.el6.x86_64
glibc-2.12-1.209.0.1.el6.x86_64
glibc-common-2.12-1.209.0.1.el6.x86_64
glibc-devel-2.12-1.209.0.1.el6.x86_64 动态编译
gcc -w `pkg-config --cflags --libs glib-2.0` source/binlogParseGlib.c -o binary/flashback [root@redis01 binary]# ./flashback -h
Usage:
flashback [OPTION...] Help Options:
-h, --help Show help options Application Options:
--databaseNames databaseName to apply. if multiple, seperate by comma(,)
--tableNames tableName to apply. if multiple, seperate by comma(,)
--start-position start position
--stop-position stop position
--start-datetime start time (format %Y-%m-%d %H:%M:%S)
--stop-datetime stop time (format %Y-%m-%d %H:%M:%S)
--sqlTypes sql type to filter . support INSERT, UPDATE ,DELETE. if multiple, seperate by comma(,)
--maxSplitSize max file size after split, the uint is M
--binlogFileNames binlog files to process. if multiple, seperate by comma(,)
--outBinlogFileNameBase output binlog file name base
--logLevel log level, available option is debug,warning,error
--include-gtids gtids to process
--exclude-gtids gtids to skip
生成100万行数据
[root@redis01 sysbench]# sysbench oltp_common --tables=1 --table-size=1000000 --db-driver=mysql --mysql-db=ht --mysql-user=root --mysql-password=ocm123 prepare
sysbench 1.0.14 (using bundled LuaJIT 2.1.0-beta2) Creating table 'sbtest1'...
Inserting 1000000 records into 'sbtest1'
Creating a secondary index on 'sbtest1'...
查看binglog的pos
mysql> reset master;
Query OK, 0 rows affected (0.17 sec) mysql> show master logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000001 | 150 |
+------------------+-----------+
1 row in set (0.00 sec) mysql> show master logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000001 | 190803685 |
+------------------+-----------+
1 row in set (0.00 sec)
查看表中数据
mysql> select * from ht.sbtest1 where id < 10;
+----+--------+-------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------+
| id | k | c | pad |
+----+--------+-------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------+
| 1 | 499284 | 83868641912-28773972837-60736120486-75162659906-27563526494-20381887404-41576422241-93426793964-56405065102-33518432330 | 67847967377-48000963322-62604785301-91415491898-96926520291 |
| 2 | 501969 | 38014276128-25250245652-62722561801-27818678124-24890218270-18312424692-92565570600-36243745486-21199862476-38576014630 | 23183251411-36241541236-31706421314-92007079971-60663066966 |
| 3 | 504261 | 33973744704-80540844748-72700647445-87330233173-87249600839-07301471459-22846777364-58808996678-64607045326-48799346817 | 38615512647-91458489257-90681424432-95014675832-60408598704 |
| 4 | 502014 | 37002370280-58842166667-00026392672-77506866252-09658311935-56926959306-83464667271-94685475868-28264244556-14550208498 | 63947013338-98809887124-59806726763-79831528812-45582457048 |
| 5 | 499813 | 44257470806-17967007152-32809666989-26174672567-29883439075-95767161284-94957565003-35708767253-53935174705-16168070783 | 34551750492-67990399350-81179284955-79299808058-21257255869 |
| 6 | 500585 | 37216201353-39109531021-11197415756-87798784755-02463049870-83329763120-57551308766-61100580113-80090253566-30971527105 | 05161542529-00085727016-35134775864-52531204064-98744439797 |
| 7 | 501371 | 33071042495-29920376648-91343430102-79082003121-73317691963-02846712788-88069761578-14885283975-44409837760-90760298045 | 91798303270-64988107984-08161247972-12116454627-22996445111 |
| 8 | 499938 | 73754818686-04889373966-18668178968-56957589012-31352882173-91882653509-59577900152-88962682169-52981807259-62646890059 | 76460662325-41613089656-42706083314-81833284991-17063140920 |
| 9 | 527268 | 26482547570-00155460224-12388481921-23289186371-78242522654-77998886134-73270876420-50821093220-31442690639-11588920653 | 30508501104-50823269125-88107014550-70202920684-95842308929 |
+----+--------+-------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------+
9 rows in set (0.00 sec)
更新行,并且查看binglog
mysql> update ht.sbtest1 set pad='qdds';
Query OK, 1000000 rows affected (33.62 sec)
Rows matched: 1000000 Changed: 1000000 Warnings: 0 mysql> select * from ht.sbtest1 where id < 10;
+----+--------+-------------------------------------------------------------------------------------------------------------------------+------+
| id | k | c | pad |
+----+--------+-------------------------------------------------------------------------------------------------------------------------+------+
| 1 | 499284 | 83868641912-28773972837-60736120486-75162659906-27563526494-20381887404-41576422241-93426793964-56405065102-33518432330 | qdds |
| 2 | 501969 | 38014276128-25250245652-62722561801-27818678124-24890218270-18312424692-92565570600-36243745486-21199862476-38576014630 | qdds |
| 3 | 504261 | 33973744704-80540844748-72700647445-87330233173-87249600839-07301471459-22846777364-58808996678-64607045326-48799346817 | qdds |
| 4 | 502014 | 37002370280-58842166667-00026392672-77506866252-09658311935-56926959306-83464667271-94685475868-28264244556-14550208498 | qdds |
| 5 | 499813 | 44257470806-17967007152-32809666989-26174672567-29883439075-95767161284-94957565003-35708767253-53935174705-16168070783 | qdds |
| 6 | 500585 | 37216201353-39109531021-11197415756-87798784755-02463049870-83329763120-57551308766-61100580113-80090253566-30971527105 | qdds |
| 7 | 501371 | 33071042495-29920376648-91343430102-79082003121-73317691963-02846712788-88069761578-14885283975-44409837760-90760298045 | qdds |
| 8 | 499938 | 73754818686-04889373966-18668178968-56957589012-31352882173-91882653509-59577900152-88962682169-52981807259-62646890059 | qdds |
| 9 | 527268 | 26482547570-00155460224-12388481921-23289186371-78242522654-77998886134-73270876420-50821093220-31442690639-11588920653 | qdds |
+----+--------+-------------------------------------------------------------------------------------------------------------------------+------+
9 rows in set (0.43 sec) mysql> show master logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000001 | 517083888 |
+------------------+-----------+
1 row in set (0.00 sec)
准备脚本闪回
[root@redis01 binary]# cat 1.sh
echo `date`
export MYSQL_PWD=ocm123
./flashback --databaseNames=ht --tableNames=sbtest1 --sqlTypes=update --binlogFileNames=/data/mysql/mysql-bin.000001 --outBinlogFileNameBase=./org --start-position=190803685
./flashback --binlogFileNames=org.flashback --maxSplitSize=30
arr=`find ${file_path} -name "binlog_output_base.0*"|sort -n`
for i in ${arr}
do
mysqlbinlog --skip-gtids ${i} | mysql ht
done
echo `date` [root@redis01 binary]# ./1.sh
Thu Jul 12 18:36:46 CST 2018
Thu Jul 12 18:42:29 CST 2018
闪回100万行数据只用6分钟
闪回完毕查看数据
mysql> select * from ht.sbtest1 where id < 10;
+----+--------+-------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------+
| id | k | c | pad |
+----+--------+-------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------+
| 1 | 499284 | 83868641912-28773972837-60736120486-75162659906-27563526494-20381887404-41576422241-93426793964-56405065102-33518432330 | 67847967377-48000963322-62604785301-91415491898-96926520291 |
| 2 | 501969 | 38014276128-25250245652-62722561801-27818678124-24890218270-18312424692-92565570600-36243745486-21199862476-38576014630 | 23183251411-36241541236-31706421314-92007079971-60663066966 |
| 3 | 504261 | 33973744704-80540844748-72700647445-87330233173-87249600839-07301471459-22846777364-58808996678-64607045326-48799346817 | 38615512647-91458489257-90681424432-95014675832-60408598704 |
| 4 | 502014 | 37002370280-58842166667-00026392672-77506866252-09658311935-56926959306-83464667271-94685475868-28264244556-14550208498 | 63947013338-98809887124-59806726763-79831528812-45582457048 |
| 5 | 499813 | 44257470806-17967007152-32809666989-26174672567-29883439075-95767161284-94957565003-35708767253-53935174705-16168070783 | 34551750492-67990399350-81179284955-79299808058-21257255869 |
| 6 | 500585 | 37216201353-39109531021-11197415756-87798784755-02463049870-83329763120-57551308766-61100580113-80090253566-30971527105 | 05161542529-00085727016-35134775864-52531204064-98744439797 |
| 7 | 501371 | 33071042495-29920376648-91343430102-79082003121-73317691963-02846712788-88069761578-14885283975-44409837760-90760298045 | 91798303270-64988107984-08161247972-12116454627-22996445111 |
| 8 | 499938 | 73754818686-04889373966-18668178968-56957589012-31352882173-91882653509-59577900152-88962682169-52981807259-62646890059 | 76460662325-41613089656-42706083314-81833284991-17063140920 |
| 9 | 527268 | 26482547570-00155460224-12388481921-23289186371-78242522654-77998886134-73270876420-50821093220-31442690639-11588920653 | 30508501104-50823269125-88107014550-70202920684-95842308929 |
+----+--------+-------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------+
9 rows in set (0.00 sec)
mysql> show master logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000001 | 851563888 |
+------------------+-----------+
1 row in set (0.00 sec)
测试过程当中出现的问题
ERROR 1782 (HY000) at line 18: @@SESSION.GTID_NEXT cannot be set to ANONYMOUS when @@GLOBAL.GTID_MODE = ON.
解决:mysqlbinlog 加--skip-gtids
[root@redis01 binary]# mysqlbinlog --skip-gtids binlog_output_base.flashback | mysql ht
ERROR 2006 (HY000) at line 8017: MySQL server has gone away
解决:加大max_allowed_packet
mysql> show global variables like 'max_allowed_packet';
+--------------------+---------+
| Variable_name | Value |
+--------------------+---------+
| max_allowed_packet | 4194304 |
+--------------------+---------+
1 row in set (0.00 sec) set global max_allowed_packet=67108864;
还有用下面脚本执行完毕不回滚数据
./flashback --databaseNames=ht --tableNames=sbtest1 --sqlTypes=update --binlogFileNames=/data/mysql/mysql-bin.000001 --maxSplitSize=30 --start-position=190803685
mysqlbinlog --skip-gtids ${i} | mysql ht
疑惑的是直接切割生成的日志文件不能回滚数据;得用下面的脚本在单独其切割成小文件才能回滚数据;后面有空得看看源码尝试自己修改下
./flashback --databaseNames=ht --tableNames=sbtest1 --sqlTypes=update --binlogFileNames=/data/mysql/mysql-bin.000001 --outBinlogFileNameBase=./org --start-position=190803685
./flashback --binlogFileNames=org.flashback --maxSplitSize=30
mysql5.7 闪回数据(update delete insert)的更多相关文章
- [转]SQLServer添加UPDATE回滚日志(update/delete/insert)
下面直接上代码(copy到你的数据库里面直接就可以运行): CREATE PROCEDURE [dbo].[SP_UPDATE_LOG] ) AS BEGIN SET NOCOUNT ON; IF N ...
- oracle flashback data archive闪回数据归档天坑之XID重用导致闪回查询数据重复
我们有个系统使用了Oracle flashback data archive闪回数据归档特性来作为基于时间点的恢复机制,在频繁插入.更新期间发现SYS_FBA_HIST_NNNN表中的XID被两个事务 ...
- oracle闪回、闪回数据归档Flashback Data Archive (Oracle Total Recall)的真正强大之处、11gR2增强以及合理使用
oracle的闪回很早就出来了,准确的说一直以来应该都较少被真正用户广为使用,除了dba和极少部分开发人员偶尔用于逻辑出错.误删恢复之外,较少被用于产生更有价值的用途. 各种闪回表flashback ...
- flashback query闪回数据
误删除了部分重要数据,已提交,需要恢复.首先尝试flashback query闪回数据. 数据库运行在归档模式,首先确认数据库的SCN的变化: SQL> col fscn for 9999999 ...
- Oracle闪回查询恢复delete删除数据
Flashback query(闪回查询)原理 Oracle根据undo信息,利用undo数据,类似一致性读取方法,可以把表置于一个删除前的时间点(或SCN),从而将数据找回. Flashback q ...
- PLSQL_闪回删除FlashBack Delete表误删除如何进行恢复(案例)
2014-07-02 Created By BaoXinjian
- 除了binlog2sql工具外,使用python脚本闪回数据(数据库误操作)
利用binlog日志恢复数据库误操作数据 在人工手动进行一些数据库写操作的时候(比方说数据修改),尤其是一些不可控的批量更新或删除,通常都建议备份后操作.不过不怕万一,就怕一万,有备无患总是好的.在线 ...
- Oracl闪回数据命令。
当数据库操作没有备份,并且误删数据.可闪回任何 当前闪回15分钟前数据库状态. alter table BASE_APPOINT_LOG enable row movement;flashback ...
- [Hibernate] - Select/Update/Delete/Insert
Java bean: package com.my.bean; import java.util.Date; public class WorkPack { private String uWorkP ...
随机推荐
- 020、搭建本地Registry(2019-01-11 周五)
参考https://www.cnblogs.com/CloudMan6/p/6902325.html Docker Hub 虽然方便,但还是有些限制,比如 1.需要Internet连接,上 ...
- 15.scrapy模拟登陆案例
1.案例一 a.创建项目 scrapy startproject renren_login 进入项目路径 scrapy genspider renren "renren.com" ...
- lua基于oopclass的属性节点类 和 集合类
--[[---------------------------------------------------------------------------- --@ Descrption: 属性节 ...
- deque
转自:https://www.cnblogs.com/LearningTheLoad/p/7450948.html deque双向开口可进可出的容器 我们知道连续内存的容器不能随意扩充,因为这样容易扩 ...
- java设计模式之单例模式以及实现的几种方法
java设计模式以及实现的几种方法,看到比较好的博客文章,收藏起来供以后再次阅读.. 参见:http://www.cnblogs.com/garryfu/p/7976546.html
- luogu P3237 [HNOI2014]米特运输
传送门 谢特运输 先要搞懂题目是什么意思,简化版题意就是一棵有根树,要使得每个点都满足任意一个儿子的权值等于这个点权值除以儿子数量,问最少要修改多少个点的点权 就可以一边dfs求出每个点权值是点1的多 ...
- 调用kaldi的模型进行解码
At the moment Kaldi is targeted more at people who are building ASR systems than those who just want ...
- 阿里云三台CentOS7.2配置安装CDH5.12
1 购买3台阿里云服务 2 配置好ssh连接客户端 根据自己情况连接 3 安装好MySQL5.7 跳过,见之前博客 安装在hadoop001上 4 设置好Hosts文件 3台机器同时操作 vim /e ...
- python 的基础 学习 第六天 基础数据类型的操作方法 字典
1,字典 字典是python中唯一的映射类型,采用键值对(key-value)的形式存储数据.python对key进行哈希函数运算,根据计算的结果决定value的存储地址,所以字典是无序存储的,且ke ...
- NIO & Netty框架学习
channle buffer selector.selectionKey 关于websocket http://lixiaohui.iteye.com/blog/2328068 长连接和短连接 htt ...