打开 binary log

记录 binary log 的风格有3种

1.sql语句模式

2.行模式 

3.混合模式

 

我在MySQL上做了这个操作

mysql> use test;
Database changed
mysql> select * from t1;
Empty set (0.00 sec)

mysql> insert into t1 values (1);
Query OK, 1 row affected (0.04 sec)

mysql> insert into t1 values (2);
Query OK, 1 row affected (0.00 sec)

mysql> insert into t1 values (3);
Query OK, 1 row affected (0.00 sec)

mysql> insert into t1 values (4);
Query OK, 1 row affected (0.00 sec)

反映在binary log上是这些内容

[root@centos7 data]# mysqlbinlog --no-defaults  ./mysql-bin.000019
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#160109 10:16:58 server id 1  end_log_pos 107   Start: binlog v 4, server v 5.5.47-log created 160109 10:16:58
# Warning: this binlog is either in use or was not closed properly.
BINLOG '
mm2QVg8BAAAAZwAAAGsAAAABAAQANS41LjQ3LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAEzgNAAgAEgAEBAQEEgAAVAAEGggAAAAICAgCAA==
'/*!*/;
# at 107
#160109 10:28:44 server id 1  end_log_pos 187   Query   thread_id=2     exec_time=0     error_code=0
use `test`/*!*/;
SET TIMESTAMP=1452306524/*!*/;
SET @@session.pseudo_thread_id=2/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=0/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=33/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
truncate table t1
/*!*/;
# at 187
#160109 11:51:14 server id 1  end_log_pos 255   Query   thread_id=5     exec_time=0     error_code=0
SET TIMESTAMP=1452311474/*!*/;
BEGIN
/*!*/;
# at 255
#160109 11:51:14 server id 1  end_log_pos 343   Query   thread_id=5     exec_time=0     error_code=0
SET TIMESTAMP=1452311474/*!*/;
insert into t1 values (1)
/*!*/;
# at 343
#160109 11:51:14 server id 1  end_log_pos 370   Xid = 32
COMMIT/*!*/;
# at 370
#160109 11:51:17 server id 1  end_log_pos 438   Query   thread_id=5     exec_time=0     error_code=0
SET TIMESTAMP=1452311477/*!*/;
BEGIN
/*!*/;
# at 438
#160109 11:51:17 server id 1  end_log_pos 526   Query   thread_id=5     exec_time=0     error_code=0
SET TIMESTAMP=1452311477/*!*/;
insert into t1 values (2)
/*!*/;
# at 526
#160109 11:51:17 server id 1  end_log_pos 553   Xid = 33
COMMIT/*!*/;
# at 553
#160109 11:51:20 server id 1  end_log_pos 621   Query   thread_id=5     exec_time=0     error_code=0
SET TIMESTAMP=1452311480/*!*/;
BEGIN
/*!*/;
# at 621
#160109 11:51:20 server id 1  end_log_pos 709   Query   thread_id=5     exec_time=0     error_code=0
SET TIMESTAMP=1452311480/*!*/;
insert into t1 values (3)
/*!*/;
# at 709
#160109 11:51:20 server id 1  end_log_pos 736   Xid = 34
COMMIT/*!*/;
# at 736
#160109 11:51:22 server id 1  end_log_pos 804   Query   thread_id=5     exec_time=0     error_code=0
SET TIMESTAMP=1452311482/*!*/;
BEGIN
/*!*/;
# at 804
#160109 11:51:22 server id 1  end_log_pos 892   Query   thread_id=5     exec_time=0     error_code=0
SET TIMESTAMP=1452311482/*!*/;
insert into t1 values (4)
/*!*/;
# at 892
#160109 11:51:22 server id 1  end_log_pos 919   Xid = 35
COMMIT/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;

里面的各种记录分开说明

# at 107
# at 187
# at 255
# at 343

at 的意思是“在某个位置”,那107,187,255 这些都是位置来的,document把这些称之为“偏移值”,这些“位置”存在的意义在于,在做数据恢复的时候,往往不是恢复整个binary log,而是截取日志文件的某一部分,那这些107,187就是用来定位的,还有就是做replication的时候,slave除了需要知道master正在使用哪个binary log,还要知道binary log写到哪个position

the number following at indicates the file offset, or starting position, of the event in the binary log file.

 

# at 621
#160109 11:51:20 server id 1  end_log_pos 709   Query   thread_id=5     exec_time=0     error_code=0
SET TIMESTAMP=1452311480/*!*/;
insert into t1 values (3)
/*!*/;
# at 709
#160109 11:51:20 server id 1  end_log_pos 736   Xid = 34
COMMIT/*!*/;

160109 是 date 来的,意思是  2016年01月09日,如果binary log 太大的话,我们不可能全部打开,我们选择的更多是用“日期”来截取binary log ,从什么时候开始“--start-datetime”,从什么时候结束 “--stop-datetime=datetime”,而 end_log_pos 的意思是,我这个 “insert into t1 values (3)” 这个event 的”日志结束位置“ ,pos是position的缩写,这个结束的位置,也是下一个event开始的位置,所以下一个event 是 # at 709

 

如果把process看做是一个团队,一起完成 mysqld 这个项目的话,那么团队里面的每一个人就是一个thread,thread_id 就是员工号,在这里 "insert into t1 values (3)" 这个事情,就有一位员工号是5的 thread来处理,处理的时间用 exec_time 来反映

 

《row模式下的binary log》===================================

 

首先把binary log的方式设置成为row ,插入数据

机器有很多个binary log日志,但查询哪个日志,而且在那个日志在哪个位置,这需要查询的

因为日志是二进制的,所以得用工具打开,这里选择导出为文本的方式,方便查询position

如果不加--no-defaults选项,就会报错不能识别utf-8编码,接着用vi搜索出位置

 它是一串类似加密的东西,还有一点要提的是一个线程处理一个事务,如果想要看这串加密到底是什么内容,可以加一个--verbose的参数

 其实所谓的row模式,有点像加密了的只有insert的“statement”模式

 

详细内容看这里:mysqlbinlog — Utility for Processing Binary Log Files

 

转载于:https://www.cnblogs.com/hellotracy/articles/5116264.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值