mysql二进制日志之row模式日志内容分析(一)

mysql⼆进制⽇志之row模式⽇志内容分析(⼀)验证相关参数
binlog_format=row
binlog_row_image=full
binlog_rows_query_log_events=on
先上总结
binlog_format=row
01:直接⽤"mysqlbinlog PATH/binlogfile"来查看时
02:binlog⽇志⽂件中对于DML数据操纵语⾔的语句是加密的(需要解密才能看到)
03:binlog⽇志⽂件中对于DDL数据定义语⾔的语句是明⽂的(也就是可以直接看到)
binlog_row_image=full
01:⽤"mysqlbinlog --base64-output=decode-row -vv PATH/binlogfile"来查看时
02:binlog⽇志⽂件中对于DML数据操作语⾔insert会记录具体插⼊了什么值(整⾏的所有字段的值)
03:binlog⽇志⽂件中对于DML数据操作语⾔update会记录更新和更新后的值(整⾏的所有字段的值,即使你只更新了某⼀个字段的值)
04:binlog⽇志⽂件中对于DML数据操作语⾔delete会记录具体删除了什么值(整⾏的所有字段的值)
binlog_rows_query_log_events=on
01:⽤"mysqlbinlog --base64-output=decode-row -vv PATH/binlogfile"来查看时
02:binlog⽇志⽂件中对于DML数据操纵语⾔语句,会显⽰具体执⾏的SQL语句。
03:我们在mysql中⽤show binlog events in "binlogfile";命令可以看到DDL语句,也可以看到DML语句。
问题⼀:如何保证主从复制之间数据的⼀致性
答⼀:ps:当然还有⼀些其它的因素要考虑到哈
01:主从复制要同步函数
公司规则了不要使⽤函数,但是你能控制住⼈嘛,新来的开发⼈员呢?
02:⼆进制⽇志模式要使⽤row模式
因为⼆进制⽇志⽂件中会记录具体更改的值
当前环境介绍
mysql> select version();  #mysql版本
+------------+
| version()  |
+------------+
| 5.7.22-log |
+------------+
1 row in set (0.00 sec)
mysql> select @@global.autocommit,@@autocommit;  #开启了⾃动提交
+---------------------+--------------+
| @@global.autocommit | @@autocommit |
+---------------------+--------------+
|                  1 |            1 |
+---------------------+--------------+
1 row in set (0.00 sec)
mysql> show master status;  #当前的binlog⽇志⽂件及pos点
+---------------------+----------+--------------+------------------+-------------------+
| File                | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------------+----------+--------------+------------------+-------------------+
| 21_mysql_bin.000001 |      154 |              |                  |                  |
+---------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
验证参数的状态
mysql> select @@global.binlog_format,@@binlog_format;  #全局和当前会话下
+------------------------+-----------------+
| @@global.binlog_format | @@binlog_format |
+------------------------+-----------------+
| ROW                    | ROW            |
+------------------------+-----------------+
1 row in set (0.00 sec)
mysql> select @@global.binlog_row_image,@@binlog_row_image; #全局和当前会话下
+---------------------------+--------------------+
| @@global.binlog_row_image | @@binlog_row_image |
+---------------------------+--------------------+
| FULL                      | FULL              |
+---------------------------+--------------------+
1 row in set (0.00 sec)
mysql> select @@global.binlog_rows_query_log_events,@@binlog_rows_query_log_events;  #全局和当前会话下+---------------------------------------+--------------------------------+
| @@global.binlog_rows_query_log_events | @@binlog_rows_query_log_events |
+---------------------------------------+--------------------------------+
|                                    1 |                              1 |
+---------------------------------------+--------------------------------+
1 row in set (0.00 sec)
测试数据
-- 创建chenliang库
create database if not exists chenliang character set utf8 collate utf8_general_ci;
-- 进⼊chenliang库
use chenliang;
-- 查看是否成功进⼊到chenliang库下⾯
select database();
-- 创建test1表
create table if not exists test1(
西乡县卫生局id int(10) unsigned not null auto_increment primary key comment"序列号",
name varchar(20) not null comment"姓名",
age int(3) unsigned not null comment"年龄",
jobdate date not null comment"参加⼯作的时间"
)engine=innodb character set utf8 collate utf8_general_ci comment"测试表1";
-- 插⼊两⾏数据
insert into test1(name,age,jobdate) values
("chenliang01",25,curdate()),
("chenliang02",26,curdate());
-- 更改age字段的内容为26,条件是name等于chenliang01,id等于1
update test1 set age=26 where id=1 and name="chenliang01";
-
- 删除id等于2,name内容等于chenliang02的记录
delete from test1 where id=2 and name="chenliang02";
-- truncate表
truncate test1;
mysql> show master status;
+---------------------+----------+--------------+------------------+-------------------+
| File                | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------------+----------+--------------+------------------+-------------------+
| 21_mysql_bin.000001 |    2230 |              |                  |                  |
+---------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
⽤mysqlbinlog命令来查看⼆进制⽇志⽂件(⼀)
[root@master binlog]# mysqlbinlog  21_mysql_bin.000001
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#190913  2:38:46 server id 21  end_log_pos 123 CRC32 0x7876ff8f        Start: binlog v 4, server v 5.7.22-log created 190913  2:38:46 at startup
# Warning: this binlog is either in use or was not closed properly.
大学生跳楼自杀ROLLBACK/*!*/;
BINLOG '
djl7XQ8VAAAAdwAAAHsAAAABAAQANS43LjIyLWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAB2OXtdEzgNAAgAEgAEBAQEEgAAXwAEGggAAAAICAgCAAAACgoKKioAEjQA
AY//dng=
'/*!*/;
# at 123
#190913  2:38:46 server id 21  end_log_pos 154 CRC32 0xc794dcdd        Previous-GTIDs
# [empty]
# at 154
-- 这是创建chenliang库的sql记录(没有解析,对于DDL语句是可以看到完整的语句的)
#190913  2:39:00 server id 21  end_log_pos 219 CRC32 0x0d65e789        Anonymous_GTID  last_committed=0        sequence_number=1rbr_only=no
#190913  2:39:00 server id 21  end_log_pos 219 CRC32 0x0d65e789        Anonymous_GTID  last_committed=0        sequence_number=1rbr_only=no SET @@SESSION.GTID_NEXT= 'ANONY
MOUS'/*!*/;
# at 219
#190913  2:39:00 server id 21  end_log_pos 385 CRC32 0x27d8846e        Query  thread_id=5    exec_time=0    error_code=0
SET TIMESTAMP=1568356740/*!*/;
SET @@session.pseudo_thread_id=5/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=1436549120/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=33,@@llation_connection=33,@@llatio
n_server=33/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@llation_database=DEFAULT/*!*/;
create database if not exists chenliang character set utf8 collate utf8_general_ci
/*!*/;
# at 385
-- 这是创建test表的语句(没⽤解析,对于DDL语句是可以直接看到完整的语句的)
#190913  2:39:22 server id 21  end_log_pos 450 CRC32 0x1c0e30ec        Anonymous_GTID  last_committed=1        sequence_number=2rbr_only=no SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/;
# at 450
#190913  2:39:22 server id 21  end_log_pos 871 CRC32 0xb9db2ee8        Query  thread_id=5    exe
c_time=0    error_code=0
use `chenliang`/*!*/;
SET TIMESTAMP=1568356762/*!*/;
create table if not exists test1(
id int(10) unsigned not null auto_increment primary key comment"序列号",
name varchar(20) not null comment"姓名",
age int(3) unsigned not null comment"年龄",
jobdate date not null comment"参加⼯作的时间"
)engine=innodb character set utf8 collate utf8_general_ci comment"测试表1"
/*!*/;
# at 871
-
- 这是insert时的记录(没有解析,对于DML语句是加密的,看不到完整的sql语句,也看不到具体插⼊的什么值)
#190913  2:39:33 server id 21  end_log_pos 936 CRC32 0x8a9af7ab        Anonymous_GTID  last_committed=2        sequence_number=3rbr_only=yes /*!50718 SET TRANSACTION ISOLATION LEVEL READ COMMITTED*//*!*/;
SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/;
# at 936
四甲基胍
#190913  2:39:33 server id 21  end_log_pos 1021 CRC32 0xa1afe68d        Query  thread_id=5    exec_time=0    error_code=0
SET TIMESTAMP=1568356773/*!*/;
SET @@session.time_zone='SYSTEM'/*!*/;
BEGIN
/*!*/;
# at 1021
# at 1146
#190913  2:39:33 server id 21  end_log_pos 1204 CRC32 0x56e8186c        Table_map: `chenliang`.`test1` mapped to number 220
# at 1204
#190913  2:39:33 server id 21  end_log_pos 1287 CRC32 0x5b0be2ac        Write_rows: table id 220 flags: STMT_END_F
BINLOG '
pTl7XRMVAAAAOgAAALQEAAAAANwAAAAAAAEACWNoZW5saWFuZwAFdGVzdDEABAMPAwoCPAAAbBjo
Vg==
pTl7XR4VAAAAUwAAAAcFAAAAANwAAAAAAAEAAgAE//ABAAAAC2NoZW5saWFuZzAxGQAAAC3HD/AC
AAAAC2NoZW5saWFuZzAyGgAAAC3HD6ziC1s=
'/*!*/;
# at 1287
#190913  2:39:33 server id 21  end_log_pos 1318 CRC32 0x18fc91ae        Xid = 526
COMMIT/*!*/;
# at 1318
-- 这是update时的语句(没有解析,对于DML语句是加密的,看不到完整的sql语句,也看不到更新的前和更新后的数据)
商标法论文#190913  2:39:48 server id 21  end_log_pos 1383 CRC32 0x7de03699        Anonymous_GTID  last_committed=3        sequence_number=4rbr_only=yes /*!50718 SET TRANSACTION ISOLATION LEVEL READ COMMITTED*//*!*/;
SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/;
# at 1383
#190913  2:39:48 server id 21  end_log_pos 1460 CRC32 0xba7eff82        Query  thread_id=5    exec_time=0    error_code=0
SET TIMESTAMP=1568356788/*!*/;
BEGIN
/*!*/;
# at 1460
# at 1541
#190913  2:39:48 server id 21  end_log_pos 1599 CRC32 0xbcc4e9d8        Table_map: `chenliang`.`test1` mapped to number 220
# at 1599
#190913  2:39:48 server id 21  end_log_pos 1683 CRC32 0x190ca2e1        Update_rows: table id 220 flags: STMT_END_F
BINLOG '
tDl7XRMVAAAAOgAAAD8GAAAAANwAAAAAAAEACWNoZW5saWFuZwAFdGVzdDEABAMPAwoCPAAA2OnE
vA==
tDl7XR8VAAAAVAAAAJMGAAAAANwAAAAAAAEAAgAE///wAQAAAAtjaGVubGlhbmcwMRkAAAAtxw/w AQAAAAtjaGVubGlhbmcwMRoAAAAtxw/hogwZ
'/*!*/;
# at 1683
#190913  2:39:48 server id 21  end_log_pos 1714 CRC32 0x0a573be1        Xid = 535
COMMIT/*!*/;
# at 1714
-- 这是delete语句(没有解析,对于DML语句是加密的,看不到完整的sql语句,也看不到删除前的数据)
#190913  2:40:25 server id 21  end_log_pos 1779 CRC32 0xac860f3f        Anonymous_GTID  last_committed=4        sequence_number=5rbr_only=yes /*!50718 SET TRANSACTION ISOLATION LEVEL READ COMMITTED*//*!*/;
SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/;
# at 1779
#190913  2:40:25 server id 21  end_log_pos 1856 CRC32 0xf3fd97d0        Query  thread_id=5    exec_time=0    error_code=0
SET TIMESTAMP=1568356825/*!*/;
BEGIN
湖南卫视谁是英雄
/*!*/;
# at 1856
# at 1931
#190913  2:40:25 server id 21  end_log_pos 1989 CRC32 0x87dbbd04        Table_map: `chenliang`.`test1` mapped to number 220
# at 1989
#190913  2:40:25 server id 21  end_log_pos 2048 CRC32 0x1f0b576f        Delete_rows: table id 220 flags: STMT_END_F
BINLOG '
2Tl7XRMVAAAAOgAAAMUHAAAAANwAAAAAAAEACWNoZW5saWFuZwAFdGVzdDEABAMPAwoCPAAABL3b
hw==
2Tl7XSAVAAAAOwAAAAAIAAAAANwAAAAAAAEAAgAE//ACAAAAC2NoZW5saWFuZzAyGgAAAC3HD29X
Cx8=
'/*!*/;
# at 2048
#190913  2:40:25 server id 21  end_log_pos 2079 CRC32 0x933ed8e2        Xid = 550
COMMIT/*!*/;
# at 2079
-- 这是truncate表的语句(没有解析,对于DDL语句是可以直接看到完整的语句的)
#190913  2:41:26 server id 21  end_log_pos 2144 CRC32 0xd9a0f580        Anonymous_GTID  last_committed=5        sequence_number=6rbr_only=no SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/;
# at 2144
#190913  2:41:26 server id 21  end_log_pos 2230 CRC32 0xaaf9a231        Query  thread_id=5    exec_time=0    error_code=0
SET TIMESTAMP=1568356886/*!*/;
truncate test1
/
*!*/;
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
销售与市场# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;

本文发布于:2024-09-25 01:22:32,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/325904.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

下一篇:选择题(2)
标签:语句   数据   解析   看到
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议