(4.6)mysql备份还原——深入解析二进制日志(3)binlog二进制格式详解

涉及到3个参数

  (1)binlog_format='row' -- (row,statement,mixed)

    日志记录模式,行、语句、混合

  (2)binlog_row_image=full -- (full,minimal,noblob)

    如果是用行的话,记录全部的记录、最小的记录、不记录二进制

  (3)binlog_rows_query_log_events=on -- (on,off)

    如果打开以后会记录整个语句详细的操作,如果不打开,只会记录这个操作事件(比如是更新还是插入,但无具体详细信息)

1、binlog_format='statement'

  总结:这种方式下,使用RC、RUC隔离级别会报错。且,DDL以及DML都是明文按SQL记录存储。

1.1】准备工作
-- 修改binlog记录模式
set session binlog_format='statement';
set global binlog_format='statement';
select @@global.binlog_format,@@binlog_format;

-- 修改隔离级别为重复度
set global tx_isolation='repeatable-read'; -- 旧的设置方法
set global transaction_isolation='repeatable-read'; -- 新的设置方法
set session transaction_isolation='repeatable-read';
select @@global.transaction_isolation,@@transaction_isolation;

-- 刷新binlog日志
show master status;
flush logs;
show master status;

【1.2】 测试
-- 建表
create table test2(id int primary key not null auto_increment,
tablename varchar(200),UUID varchar(50),
timepoint datetime not null default current_timestamp,
currentversion timestamp not null default current_timestamp on update current_timestamp
)engine=innodb ; -- 插入数据 insert into test2(tablename,UUID) select 'test2',uuid();
-- 更新数据
update test2 set tablename='test2_update' where id = 1;
-- 提交
commit;
-- 查看状态
show master status; -- 会发现position有了变化,之前是154,现在是2125
-- 退出mysql,进入binlog目录,使用mysqlbinlog 查看binlog信息
mysqlbinlog --start-position=154 --stop-position=2125 binlog.000002

【1.3】总结(对主从的影响)
(1)这种方式下,使用RC、RUC隔离级别会报错。
(2)DDL以及DML都是明文按SQL记录存储。
(3)对有些参数,在不同的服务器和不同的时间,执行的结果不一样,会导致主从不一致。比如currment_date,timestamp。
  特别是一些函数:uuid(),user(),时间函数now()
(4)性能问题:比如主库有一条慢SQL执行了,也会去从库执行
(5)数据异常:主从数据不一致,执行也会有问题

猜你喜欢

转载自www.cnblogs.com/gered/p/10720918.html