• 二进制回复操作


    环境部署
    开启二进制文件
    cat /etc/my.cnf.d/server.cnf
    [server]
    log_bin=mysql-bin

    第一步查看:
    MariaDB [(none)]> show master status;
    +------------------+----------+--------------+------------------+
    | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +------------------+----------+--------------+------------------+
    | mysql-bin.000004 | 342 | | |
    +------------------+----------+--------------+------------------+

    第二步回滚:
    MariaDB [(none)]> flush logs;

    第三步查看:
    MariaDB [(none)]> show master status;
    +------------------+----------+--------------+------------------+
    | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +------------------+----------+--------------+------------------+
    | mysql-bin.000005 | 385 | | |
    +------------------+----------+--------------+------------------+

    第四步创建:数据库。表。
    MariaDB [(none)]> create database xiao;
    Query OK, 1 row affected (0.001 sec)

    MariaDB [(none)]> use xiao;
    Database changed
    MariaDB [xiao]> create table students ( id int primary key auto_increment,
    name varchar(20));
    Query OK, 0 rows affected (0.012 sec)

    MariaDB [xiao]> insert into students values (0,'aaa');
    Query OK, 1 row affected (0.004 sec)

    MariaDB [xiao]> insert into students values (0,'bbb');
    Query OK, 1 row affected (0.003 sec)

    MariaDB [xiao]> insert into students values (0,'ccc');
    Query OK, 1 row affected (0.001 sec)


    MariaDB [xiao]> select * from students;
    +----+------+
    | id | name |
    +----+------+
    | 1 | aaa |
    | 2 | bbb |
    | 3 | ccc |
    +----+------+

    第五步:删除一条数据
    MariaDB [xiao]> delete from students where id=2;
    Query OK, 1 row affected (0.013 sec)

    MariaDB [xiao]> select * from students;
    +----+------+
    | id | name |
    +----+------+
    | 1 | aaa |
    | 3 | ccc |
    +----+------+

    第六步:查看回滚数据
    MariaDB [xiao]> show master status;
    +------------------+----------+--------------+------------------+
    | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +------------------+----------+--------------+------------------+
    | mysql-bin.000005 | 1622 | | |
    +------------------+----------+--------------+------------------+
    cd /var/lib/mysql
    [root@zxw8 mysql]# mysqlbinlog mysql-bin.000005
    # at 1493
    #190709 2:20:29 server id 1 end_log_pos 1591 CRC32 0xfdd65b71 Querthread_id=9 exec_time=0 error_code=0
    SET TIMESTAMP=1562653229/*!*/;
    delete from students where id=2
    /*!*/;

    第七步:回复数据
    [root@zxw8 mysql]# mysqlbinlog /var/lib/mysql/mysql-bin.000005 --start-position=1107 --stop-position=1451 | mysql -uroot -p123
    ERROR 1062 (23000) at line 46: Duplicate entry '3' for key 'PRIMARY'
    MariaDB [xiao]> select * from students;
    +----+------+
    | id | name |
    +----+------+
    | 1 | aaa |
    | 3 | ccc |
    | 7 | bbb |

    mysqlbinlog --start-datetime="2019-06-08 22:55:13" --stop-datetime="2019-06-08 22:55:13" binlog.0000011 > bin.sql

    执行bin.sql文件还原
    source bin.sql

     

     

  • 相关阅读:
    跨平台编译ceres for Android
    解决OpenCV JavaCameraView相机preview方向问题
    OpenCV 4.0.1 找不到R.styleable解决
    mumu模拟器安装xposed--如何在android模拟器上进行root
    Windows编译OpenCV4Android解决undefined reference to std错误
    Skeleton with Assimp 骨骼动画解析
    Android GL deadlock timeout error
    Android device debug (adb) by Charge Only mode
    Firefox 多行标签的解决方案分享
    Linux 工程向 Windows 平台迁移的一些小小 tips
  • 原文地址:https://www.cnblogs.com/itzhao/p/11293693.html
Copyright © 2020-2023  润新知