码迷,mamicode.com
首页 > 其他好文 > 详细

二进制回复操作

时间:2019-08-03 11:01:21      阅读:89      评论:0      收藏:0      [点我收藏+]

标签:stop   mariadb   value   ignore   tab   还原   prim   val   end   

环境部署
开启二进制文件
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

 

 

二进制回复操作

标签:stop   mariadb   value   ignore   tab   还原   prim   val   end   

原文地址:https://www.cnblogs.com/itzhao/p/11293693.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!