继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

【转发】Mysql 如何使用 binlog 日志回滚操作失误的数据

五岁小孩
关注TA
已关注
手记 35
粉丝 0
获赞 2

一、背景

在日常开发运维中,我们可能会出现一些操作失误的情况,比如使用了错误的 sql 语句对 mysql 数据进行了 update、delete 等操作,失误操作导致数据出现问题,又或者架构设计上没有使用软删除机制,用户误删除了数据需要恢复。

那么如果出现这种情况,应该如何恢复失误/mysql 误删数据时,本文将使用几种常用方法一步一步带你回滚误删/误操的数据

二、准备测试数据

1. 创建测试表

create table jxy_pms.test_model
(
    create_time       bigint unsigned default 0     null,
    update_time       bigint unsigned default 0     null,
    delete_time       bigint unsigned default 0     null,
    test_model_id     varchar(255)                  not null
        primary key,
    name              varchar(255)                  null,
    remark            varchar(255)                  null
)
    collate = utf8mb4_unicode_ci;

2. 创建测试数据

insert into test_model (test_model_id, name, remark)
values ('1','test1','test-1'),
       ('2','test2','test-2'),
       ('3','test3','test-3');

select * from test_model

test_model_id  name   remark
1                 test1    test-1
2              test2    test-2
3                 test3    test-3

三、模拟误操作

delete from test_model

四、数据回滚

见原文地址

原文地址

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP