MySQL
平台:Linux
[mysqld]
server_id = 1
log_bin = /data/mysql/log/binary/mysql-bin.log
max_binlog_size = 1G
binlog_format = row
binlog_row_image = full
select:需要读取server端information_schema.COLUMNS表,获取表结构的元信息,拼接成可视化的sql语句
super/replication client:两个权限都可以,需要执行SHOW MASTER STATUS, 获取server端的binlog列表
replication slave:通过BINLOG_DUMP协议获取binlog内容的权限
mysql连接配置
解析模式
解析范围控制
对象过滤
mysql> show global variables like binlog_format;
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| binlog_format | ROW |
+---------------+-------+
1 row in set (0.00 sec)
mysql>
mysql> show master status;
+------------------+----------+
| File | Position |
+------------------+----------+
| mysql-bin.000107 | 120 |
+------------------+----------+
1 row in set (0.00 sec)
mysql> select * from tb1;
+------+------+
| id | name |
+------+------+
| 1 | aa |
| 2 | bb |
+------+------+
2 rows in set (0.00 sec)
mysql>
mysql> insert into tb1 values (3,cc);
Query OK, 1 row affected (0.00 sec)
mysql> insert into tb1 values (4,dd);
Query OK, 1 row affected (0.00 sec)
mysql> update tb1 set name=new_aa where id=1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> delete from tb1 where id=2;
Query OK, 1 row affected (0.00 sec)
mysql> select * from tb1;
+------+--------+
| id | name |
+------+--------+
| 1 | new_aa |
| 3 | cc |
| 4 | dd |
+------+--------+
3 rows in set (0.00 sec)
mysql>
[root@db_server_xuanzhi ~]#python binlog2sql.py -uroot -h127.0.0.1 -proot -dxuanzhi --start-file=mysql-bin.000107 > xuanzhi.sql
[root@db_server_xuanzhi ~]#cat xuanzhi.sql
INSERT INTO `xuanzhi`.`tb1`(`id`, `name`) VALUES (3, cc); #start 4 end 290 time 2022-01-23 10:41:34
INSERT INTO `xuanzhi`.`tb1`(`id`, `name`) VALUES (4, dd); #start 321 end 491 time 2022-01-23 10:41:38
UPDATE `xuanzhi`.`tb1` SET `id`=1, `name`=new_aa WHERE `id`=1 AND `name`=aa LIMIT 1; #start 522 end 705 time 2022-01-23 10:41:42
DELETE FROM `xuanzhi`.`tb1` WHERE `id`=2 AND `name`=bb LIMIT 1; #start 736 end 906 time 2022-01-23 10:41:50
[root@db_server_xuanzhi ~]#
[root@db_server_xuanzhi ~]#python binlog2sql.py -uroot -h127.0.0.1 -proot -dxuanzhi --start-file=mysql-bin.000107 -B > rollback_xuanzhi.sql
[root@db_server_xuanzhi ~]#cat rollback_xuanzhi.sql
INSERT INTO `xuanzhi`.`tb1`(`id`, `name`) VALUES (2, bb); #start 736 end 906 time 2022-01-23 10:41:50
UPDATE `xuanzhi`.`tb1` SET `id`=1, `name`=aa WHERE `id`=1 AND `name`=new_aa LIMIT 1; #start 522 end 705 time 2022-01-23 10:41:42
DELETE FROM `xuanzhi`.`tb1` WHERE `id`=4 AND `name`=dd LIMIT 1; #start 321 end 491 time 2022-01-23 10:41:38
DELETE FROM `xuanzhi`.`tb1` WHERE `id`=3 AND `name`=cc LIMIT 1; #start 4 end 290 time 2022-01-23 10:41:34
[root@db_server_xuanzhi ~]#
mysql> use xuanzhi
Database changed
mysql> source /tmp/rollback_xuanzhi.sql
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/129634.html
摘要:基本上每个跟数据库打交道的程序员当然也可能是你同事都会碰一个问题,误操作后如何快速回滚比如,一张表,忘加限制条件,整张表都没了。误操作后,能快速回滚数据是非常重要的。登录确认,数据回滚成功。所以,误操作的话一般只能通过备份来恢复。 基本上每个跟数据库打交道的程序员(当然也可能是你同事)都会碰一个问题,MySQL误操作后如何快速回滚?比如,delete一张表,忘加限制条件,整张表都没了。...
阅读 1346·2023-01-11 13:20
阅读 1684·2023-01-11 13:20
阅读 1132·2023-01-11 13:20
阅读 1858·2023-01-11 13:20
阅读 4100·2023-01-11 13:20
阅读 2704·2023-01-11 13:20
阅读 1385·2023-01-11 13:20
阅读 3594·2023-01-11 13:20