当前位置:网站首页>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
边栏推荐
- 6-1 从文件读取字符串(*)
- 信息安全数学基础 Chapter 1——整除
- MATLAB中histogram函数的使用
- Is it safe for Xiaobai to open an account directly on the flush?
- 说说集合的面试题
- LeetCode-1005. Maximized array sum after K negations
- 活动 | Authing 首次渠道合作活动圆满落幕
- Port planning and APJ
- Real time myth -- real-time RTOS multitask performance analysis
- AXI协议基础知识
猜你喜欢
![[online problem] timeout waiting for connection from pool](/img/f0/7e8444ed7d0921b98d5e998e274bc8.png)
[online problem] timeout waiting for connection from pool

ffmpeg奇偶场帧Interlace progressive命令和代码处理

《DAMA数据管理知识体系指南》:章节分值占比

Tornado environment construction and basic framework construction -- familiar Hello World

Song of the sea in 5g Era

Docker安装mysql5.7(开启binlog功能、修改字符)

which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mod

which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_ mod

A journey of database full SQL analysis and audit system performance optimization

How to become an optimist organization?
随机推荐
How to simplify a lot of if... Elif... Else code?
Use of forcescan in SQL server and precautions
Create database instance
vscode保存代码时自动eslint格式化
04_ Feature engineering feature selection
spawn ./gradlew EACCES at Process.ChildProcess._handle.onexit
Is it safe for Xiaobai to open an account directly on the flush?
6-3 读文章(*)
《DAMA数据管理知识体系指南》:章节分值占比
LeetCode——42. Connected to rainwater (double pointer)
av_read_frame返回值为-5 Input/output error
Activity | authing's first channel cooperation activity came to a successful conclusion
你还不懂线程池的设计及原理吗?掰开揉碎了教你设计线程池
ffmpeg硬件编解码Nvidia GPU
Connect the server with springboard / fortress through xshell
Use exe4j to convert The jar file is packaged as Exe file
API management artifact that allows you to call wow directly
Export data prompt -- solution to the problem of secure file priv option
Real time myth -- real-time RTOS multitask performance analysis
ffmpeg奇偶场帧Interlace progressive命令和代码处理