文章目录
1.1 涉及binlog的知识点带入
01:Binlog会记录DDL、DCL、DML(除select)、TCL类的SQL语句; 02:row或者mixed模式下操作的dml语句在binlog文件记录时中会加密; 且会记录DML语句具体操作的数据(例如:delete,会记录删除前相关的数据),你直接看也是看不到的; 03:statement模式下操作的dml语句在binlog文件记录时中不会加密;
1.2 -v -vv及–base64-output之间的区别
######## -v -vv --base64-output单独使用 -v # 会显示dml语句具体做了什么操作,例如:insert语句,会显示出insert具体插入了什么数据; # 但是看不到完整的dml语句,例如:insert into t1(id) values(1); # 但还是会看到dml语句的"伪"sql语句,也看不懂; -vv # 会显示dml语句具体做了什么操作,例如:insert语句,会显示insert具体插入了什么数据; # 且可以看到完整的dml语句,例如:insert into t1(id) values(1); # 但还是会看到dml语句的"伪"sql语句 --base64-output=decode-rows # 看不到dml语句的"伪" SQL语句 # 看不到dml语句具体操作了什么数据 ######## -v -vv --base64-output结合使用 -v --base64-output=decode-rows # 看得到dml语句具体做了什么操作(例如:insert时具体插入了什么数据) # 看不到dml语句的完整sql语句(例如:insert into t1(id) values(1);) # 看不到dml语句的"伪"sql语句 -vv --base64-output=decode-rows # 看得到dml语句具体做了什么操作(例如:insert时具体插入了什么数据) # 看得到dml语句的完整sql语句(例如:insert into t1(id) values(1);),但是被注释掉了的; # 看不到dml语句的"伪"sql语句
当前MySQL的版本已更新8.X.X了哈,从mysql 5.6开启只要一打开binlog,默认的binlog模式就是row模式了。
######## 数据库的版本 mysql> select @@version; +------------+ | @@version | +------------+ | 5.7.28-log | +------------+ 1 row in set (0.00 sec) ######## binlog的相关信息 -- binlog的状态、存放路径/文件名前缀 mysql> select @@global.log_bin,@@log_bin_basename; +------------------+--------------------------------------+ | @@global.log_bin | @@log_bin_basename | +------------------+--------------------------------------+ | 1 | /mysql/logs/3306/binlog/21_mysql_bin | +------------------+--------------------------------------+ 1 row in set (0.00 sec) -- binlog的模式 mysql> select @@global.binlog_format; +------------------------+ | @@global.binlog_format | +------------------------+ | ROW | +------------------------+ 1 row in set (0.00 sec) -- 当前binlog的使用情况 mysql> show master status; +---------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +---------------------+----------+--------------+------------------+-------------------+ | 21_mysql_bin.000001 | 154 | | | | +---------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) -- 操作系统下看binlog文件 mysql> system ls -l /mysql/logs/3306/binlog/21_mysql_bin.000001 -rw-r----- 1 mysql mysql 154 5月 21 22:00 /mysql/logs/3306/binlog/21_mysql_bin.000001
1.4 测试数据准备
######## 创建chenliang库后进入到库下,并查看是否成功进入 create database if not exists chenliang character set utf8 collate utf8_general_ci; use chenliang; select database(); ######## 创建test1表并插入数据 -- 创建t1表 create table if not exists t1( id int unsigned auto_increment comment"序列", name varchar(30) not null comment"姓名", sex enum("男","女") not null comment"性别", age tinyint unsigned not null comment"年龄", primary key(id) )engine=innodb character set utf8 collate utf8_general_ci comment"测试表1"; -- 往t1表中插入几条数据并提交 insert into t1(name,sex,age) values ("chenliang01","男",21), ("chenliang02","男",22), ("chenliang03","男",23), ("chenliang04","女",24), ("chenliang05","女",25), ("chenliang06","女",25); commit; -- 查看t1表中的数据 mysql> select * from t1; +----+-------------+-----+-----+ | id | name | sex | age | +----+-------------+-----+-----+ | 1 | chenliang01 | 男 | 21 | | 2 | chenliang02 | 男 | 22 | | 3 | chenliang03 | 男 | 23 | | 4 | chenliang04 | 女 | 24 | | 5 | chenliang05 | 女 | 25 | | 6 | chenliang06 | 女 | 25 | +----+-------------+-----+-----+ 6 rows in set (0.00 sec)
1.5 找出insert语句的post点
为了后面尽量的少输出文本,我们找到1.4章节中对于insert这条语句(完整事务)的起止pos点;

1.6 不用-v -vv --base64-output参数
命令
mysqlbinlog --start-position=845 --stop-position=1438 /mysql/logs/3306/binlog/21_mysql_bin.000001
- 1
截图标记说明

1.7 用-v参数来看
命令
mysqlbinlog -v --start-position=845 --stop-position=1438 /mysql/logs/3306/binlog/21_mysql_bin.000001
- 1
相关截图

1.8 用-vv参数来看
命令
mysqlbinlog -vv --start-position=845 --stop-position=1438 /mysql/logs/3306/binlog/21_mysql_bin.000001
- 1
相关截图说明

1.9 用–base-64-output参数来看
命令
mysqlbinlog --base64-output=decode-rows --start-position=845 --stop-position=1438 /mysql/logs/3306/binlog/21_mysql_bin.000001
- 1
相关截图说明

1.10 用-vv配合–base64-output来看
命令
mysqlbinlog -vv --base64-output=decode-rows --start-position=845 --stop-position=1438 /mysql/logs/3306/binlog/21_mysql_bin.000001
- 1
相关截图说明

