mysqlbinlog工具的作用是什么呢,如何将binary log转换为文本格式?

需求描述:

  今天在看mysqlbinlog这个工具,就在想这个工具到底是干嘛的呢,在mysql数据库中,

  binary log中记录了数据库内容的变化或者说修改,这些修改是以二进制的方式存储到

  binary log中的,那么要想将二进制格式转换成为文本格式,即通过文本格式显示

操作过程:

1.直接通过mysqlbinlog工具,将binary log以文本格式显示

mysqlbinlog mysql-bin.000031 > /tmp/mysql-bin.000031.txt

备注:将mysql-bin日志进行解析,并且将输出存放在txt文件中

2.查看生成的txt文件

[mysql@redhat6 data]$ more /tmp/mysql-bin.000031.txt
/*!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
#180411  9:32:38 server id 1  end_log_pos 107     Start: binlog v 4, server v 5.5.57-log created 180411  9:32:38 at startup
ROLLBACK/*!*/;
BINLOG '
tmXNWg8BAAAAZwAAAGsAAAAAAAQANS41LjU3LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAC2Zc1aEzgNAAgAEgAEBAQEEgAAVAAEGggAAAAICAgCAA==
'/*!*/;
# at 107
#180411  9:48:56 server id 1  end_log_pos 220     Query    thread_id=11    exec_time=0    error_code=0
use `employees`/*!*/;
SET TIMESTAMP=1523411336/*!*/;
SET @@session.pseudo_thread_id=11/*!*/;
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=8/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
DROP TABLE `titles` /* generated by server */
/*!*/;
# at 220
#180411  9:49:01 server id 1  end_log_pos 335     Query    thread_id=11    exec_time=0    error_code=0
SET TIMESTAMP=1523411341/*!*/;
DROP TABLE `salaries` /* generated by server */
/*!*/;
# at 335
#180411  9:49:20 server id 1  end_log_pos 408     Query    thread_id=12    exec_time=0    error_code=0
SET TIMESTAMP=1523411360/*!*/;
BEGIN
/*!*/;
# at 408
#180411  9:49:20 server id 1  end_log_pos 524     Query    thread_id=12    exec_time=0    error_code=0
SET TIMESTAMP=1523411360/*!*/;

备注:其中就记录了时间,binlog的位置.做了操作的SQL语句.

 

文档创建时间:2018年4月18日11:13:57

posted @ 2018-04-18 11:15  Zhai_David  阅读(3393)  评论(0编辑  收藏  举报