当前位置:网站首页>tidb-数据误删恢复的几种方式
tidb-数据误删恢复的几种方式
2022-06-11 17:19:00 【与数据交流的路上】
一、背景
在日常的操作中难免有些误操作,那这时候有什么办法,不通的数据库有不同的办法,多数是用备份恢复,还有一些其他特有的方法,如mysql的binlog,那么tidb有什么特有的方法呢,下面来介绍下
二、环境准备
# 建表和准备数据
create table recover_test(id int(10));
insert into recover_test values(1),(2),(3),(4);
# 查看gc相关参数,tikv_gc_life_time,tikv_gc_safe_point,tikv_gc_safe_point
select * from mysql.tidb where VARIABLE_NAME like '%gc%';
tikv_gc_life_time
三、恢复方法
1.flashback
描述: DROP 或 TRUNCATE 删除的表是在 tikv_gc_safe_point 时间之后,都能用 FLASHBACK TABLE 语法来恢复。
注意: 下游是mysql的时候会因为mysql不支持该语法造成cdc或者binlog同步失败
# 清空表
truncate table recover_test;
# 恢复表数据
flashback table recover_test to recover_test_1;
# 删除表
drop table recover_test;
# 恢复表
flashback table recover_test;
# 第二次恢复表,可以看到下面有个报错,因为 FLASHBACK 所恢复表的 table ID 还是被删除表的 table ID,而 TiDB 要求所有还存在的表 table ID 必须全局唯一,所以删除一次表,不能恢复两次
flashback table recover_test to recover_test_2;
ERROR 1050 (42S01): Table 'recover_test' already been flashback to 'recover_test', can't be flashback repeatedly
2.recover
描述: DROP 删除的表是在 tikv_gc_safe_point 时间之后,用recover 语法来恢复。
注意: 下游是mysql的时候会因为mysql不支持该语法造成cdc或者binlog同步失败
# 删除表
drop table recover_test;
# 恢复表
recover table recover_test;
3.dumpling --snapshot
描述: dml更新表或者drop,truncaate是在 tikv_gc_safe_point 时间之后,用snapshot语法来恢复。
# 删除数据
delete from recover_test where id = 3;
# 导出快照时间,注意该时间要大于tikv_gc_safe_point
dumpling --snapshot "2022-06-02 17:12:45"
# 导入导出的文件
lighting ...
4.select into outfile
描述: dml更新表或者drop,truncaate是在 tikv_gc_safe_point 时间之后,用snapshot语法来恢复。
# 删除数据
delete from recover_test where id = 3;
# 设置快照时间
set @@tidb_snapshot="2022-06-02 15:50:26";
# select into outfile导出,注意,连接的是哪个tidb,导出文件的位置就在哪个tidb上
select * from recover_test into outfile '/data/tidb/a.txt';
# 导入数据
load data ...
5.历史备份恢复
lighting
br
边栏推荐
- sql server中关于FORCESCAN的使用以及注意项
- Leetcode-- array
- Config: user attribute configuration framework
- A simple understanding of closures
- 05_ Feature Engineering - dimension reduction
- Solr (I) installation and permission control of Solr
- Global and China Mobile Network Optimization (MnO) industry development panoramic survey and Investment Strategy Research Report 2022-2028
- How to become an optimist organization?
- C语言:使用.h和.c文件遇到的问题总结
- LeetCode——24. Exchange the nodes in the linked list in pairs (three pointers)
猜你喜欢

Intranet penetration based on UDP port guessing

How to simplify a lot of if... Elif... Else code?

QLineEdit 设置输入掩码

Axi protocol Basics

Meituan won the first place in fewclue in the small sample learning list! Prompt learning+ self training practice

How to become an optimist organization?

Read and understand the development plan for software and information technology service industry during the "14th five year plan"

ffmpeg硬编解码 Inter QSV

搜狐全员遭诈骗,暴露哪些问题?

Solr (I) installation and permission control of Solr
随机推荐
spawn ./gradlew EACCES at Process.ChildProcess._handle.onexit
【Mysql】redo log,undo log 和binlog详解(四)
搜狐全员遭诈骗,暴露哪些问题?
10 times faster than 5g. Are you ready for 10 Gigabit communication?
搜狐全員遭詐騙,暴露哪些問題?
Solr (II) Solr adds core and dependent package path
6-8 创建、遍历链表
Chip mass production, oppo entering a new era?
LeetCode-859. Intimate string
CS0006 C# 未能找到元数据文件“C:\Users\...问题
端口规划与APJ
ffmpeg奇偶场帧Interlace progressive命令和代码处理
RecyclerView缓存复用解析,源码解读
Vscode configures eslint to automatically format with an error "the setting is deprecated. use editor.codeactionsonsave instead with a source“
Authoring share | understanding saml2 protocol
threejs中设置物体的贴图+场景的6面贴图 +创建空间
Export data prompt -- solution to the problem of secure file priv option
error:指针作为函数参数错误总结
sql server中移除key lookup书签查找
Don't you understand the design and principle of thread pool? Break it up and crush it. I'll teach you how to design the thread pool