记录mysql数据库真正执行更改的所有操作(DML语句),不包含那些没有修改任何数据的语句,不会记录select和show这样的语句。

二进制日志的作用:

1、 可以完成主从复制的功能

2、 进行恢复操作。

数据可以通过binglog日志,使用mysqlbinlog命令,实现基于时间点和位置的恢复操作。

查看binglog参数信息:
mysql> show global variables like '%bin%';
+-----------------------------------------+-------------------------------------------------+
| Variable_name | Value |
+-----------------------------------------+-------------------------------------------------+
| bind_address | * |
| binlog_cache_size | 4194304 |
| binlog_checksum | CRC32 |
| binlog_direct_non_transactional_updates | OFF |
| binlog_error_action | ABORT_SERVER |
| binlog_format | ROW |
| binlog_group_commit_sync_delay | 0 |
| binlog_group_commit_sync_no_delay_count | 0 |
| binlog_gtid_simple_recovery | ON |
| binlog_max_flush_queue_time | 0 |
| binlog_order_commits | ON |
| binlog_row_image | FULL |
| binlog_rows_query_log_events | OFF |
| binlog_stmt_cache_size | 32768 |
| innodb_api_enable_binlog | OFF |
| innodb_locks_unsafe_for_binlog | OFF |
| log_bin | ON |
| log_bin_basename | /mydata/mysql/mysql3307/logs/mysql-binlog |
| log_bin_index | /mydata/mysql/mysql3307/logs/mysql-binlog.index |
| log_bin_trust_function_creators | OFF |
| log_bin_use_v1_row_events | OFF |
| log_statements_unsafe_for_binlog | ON |
| max_binlog_cache_size | 1073741824 |
| max_binlog_size | 524288000 |
| max_binlog_stmt_cache_size | 18446744073709547520 |
| sync_binlog | 1 |
+-----------------------------------------+-------------------------------------------------+
26 rows in set (0.00 sec)

二进制文件用cat,head,或者tail命令是无法看的,需要通过mysqlbinglog 命令查看二进制日志,把日志转换格式后,输出到自定义的文件。
查看binglog日志文件:

mysqlbinlog --no-defaults -v -v --base64-output=decode-rows /mydata/mysql/mysql3307/logs/mysql-binlog.000021 /root/mysqlbinlog21.log

含义:
-v代表可以查看到的具体执行信息。
--base64-output 把二进制文件转换格式
以下是在ROW模式下,记录的记忆行的变更情况,变更前以及变更后的内容。
修改记录模式为:

set global binlog_format=statement;
set global binlog_format=mixed;
set global binlog_format=row;

查看生产文件内容/root/mysqlbinlog21.log

/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#180521 1:09:56 server id 3307101 end_log_pos 123 CRC32 0x79f0cd1c Start: binlog v 4, server v 5.7.20-log created 180521 1:09:56 at startup
# Warning: this binlog is either in use or was not closed properly.
ROLLBACK/*!*/;
# at 123
#180521 1:09:56 server id 3307101 end_log_pos 194 CRC32 0x96ca2d5f Previous-GTIDs
# d6a9d222-5282-11e8-bac7-080027691c44:1-15
# at 194
#180521 9:47:53 server id 3307101 end_log_pos 259 CRC32 0x737b7bad GTID last_committed=0 sequence_number=1 rbr_only=no
SET @@SESSION.GTID_NEXT= 'd6a9d222-5282-11e8-bac7-080027691c44:16'/*!*/;
# at 259
#180521 9:47:53 server id 3307101 end_log_pos 388 CRC32 0x9eba0300 Query thread_id=3 exec_time=0 error_code=0
SET TIMESTAMP=1526867273/*!*/;
SET @@session.pseudo_thread_id=3/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=1436549152/*!*/;
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=45/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
SET @@session.explicit_defaults_for_timestamp=1/*!*/;
create table test.zs(a timestamp,b timestamp,c timestamp)
/*!*/;
# at 388
#180521 9:49:28 server id 3307101 end_log_pos 453 CRC32 0x8a902dce GTID last_committed=1 sequence_number=2 rbr_only=yes
/*!50718 SET TRANSACTION ISOLATION LEVEL READ COMMITTED*//*!*/;
SET @@SESSION.GTID_NEXT= 'd6a9d222-5282-11e8-bac7-080027691c44:17'/*!*/;
# at 453
#180521 9:49:28 server id 3307101 end_log_pos 521 CRC32 0xfe907eed Query thread_id=3 exec_time=0 error_code=0
SET TIMESTAMP=1526867368/*!*/;
BEGIN
/*!*/;
# at 521
#180521 9:49:28 server id 3307101 end_log_pos 571 CRC32 0x528b2287 Table_map: `test`.`zs` mapped to number 219
# at 571
#180521 9:49:28 server id 3307101 end_log_pos 607 CRC32 0x2bb11644 Write_rows: table id 219 flags: STMT_END_F
### INSERT INTO `test`.`zs`
### SET
### @1=NULL /* TIMESTAMP(0) meta=0 nullable=1 is_null=1 */
### @2=NULL /* TIMESTAMP(0) meta=0 nullable=1 is_null=1 */
### @3=NULL /* TIMESTAMP(0) meta=0 nullable=1 is_null=1 */
# at 607
#180521 9:49:28 server id 3307101 end_log_pos 638 CRC32 0xf1b37ef5 Xid = 26
COMMIT/*!*/;
# at 638
#180521 9:49:30 server id 3307101 end_log_pos 703 CRC32 0x8d1451b6 GTID last_committed=2 sequence_number=3 rbr_only=yes
/*!50718 SET TRANSACTION ISOLATION LEVEL READ COMMITTED*//*!*/;
SET @@SESSION.GTID_NEXT= 'd6a9d222-5282-11e8-bac7-080027691c44:18'/*!*/;
# at 703
#180521 9:49:30 server id 3307101 end_log_pos 771 CRC32 0x17f458cd Query thread_id=3 exec_time=0 error_code=0
SET TIMESTAMP=1526867370/*!*/;
BEGIN
/*!*/;
# at 771
#180521 9:49:30 server id 3307101 end_log_pos 821 CRC32 0x8608f3f8 Table_map: `test`.`zs` mapped to number 219
# at 821
#180521 9:49:30 server id 3307101 end_log_pos 857 CRC32 0x61faa6a3 Write_rows: table id 219 flags: STMT_END_F
### INSERT INTO `test`.`zs`
### SET
### @1=NULL /* TIMESTAMP(0) meta=0 nullable=1 is_null=1 */
### @2=NULL /* TIMESTAMP(0) meta=0 nullable=1 is_null=1 */
### @3=NULL /* TIMESTAMP(0) meta=0 nullable=1 is_null=1 */
# at 857
#180521 9:49:30 server id 3307101 end_log_pos 888 CRC32 0xc555dada Xid = 27
COMMIT/*!*/;
# at 888
#180521 9:49:31 server id 3307101 end_log_pos 953 CRC32 0x152275a2 GTID last_committed=3 sequence_number=4 rbr_only=yes
/*!50718 SET TRANSACTION ISOLATION LEVEL READ COMMITTED*//*!*/;
SET @@SESSION.GTID_NEXT= 'd6a9d222-5282-11e8-bac7-080027691c44:19'/*!*/;
# at 953
#180521 9:49:31 server id 3307101 end_log_pos 1021 CRC32 0x68fadf15 Query thread_id=3 exec_time=0 error_code=0
SET TIMESTAMP=1526867371/*!*/;
BEGIN
/*!*/;
# at 1021
#180521 9:49:31 server id 3307101 end_log_pos 1071 CRC32 0x999fd973 Table_map: `test`.`zs` mapped to number 219
# at 1071
#180521 9:49:31 server id 3307101 end_log_pos 1107 CRC32 0x0c1bb219 Write_rows: table id 219 flags: STMT_END_F
### INSERT INTO `test`.`zs`
### SET
### @1=NULL /* TIMESTAMP(0) meta=0 nullable=1 is_null=1 */
### @2=NULL /* TIMESTAMP(0) meta=0 nullable=1 is_null=1 */
### @3=NULL /* TIMESTAMP(0) meta=0 nullable=1 is_null=1 */
# at 1107
#180521 9:49:31 server id 3307101 end_log_pos 1138 CRC32 0x0e581441 Xid = 28
COMMIT/*!*/;
# at 1138
#180521 9:51:29 server id 3307101 end_log_pos 1203 CRC32 0x6c5d54df GTID last_committed=4 sequence_number=5 rbr_only=no
SET @@SESSION.GTID_NEXT= 'd6a9d222-5282-11e8-bac7-080027691c44:20'/*!*/;
# at 1203
#180521 9:51:29 server id 3307101 end_log_pos 1290 CRC32 0x93e104d9 Query thread_id=4 exec_time=0 error_code=0
SET TIMESTAMP=1526867489/*!*/;
SET @@session.time_zone='SYSTEM'/*!*/;
flush privileges
/*!*/;
# at 1290
#180521 10:02:20 server id 3307101 end_log_pos 1355 CRC32 0x07b66739 GTID last_committed=5 sequence_number=6 rbr_only=no
SET @@SESSION.GTID_NEXT= 'd6a9d222-5282-11e8-bac7-080027691c44:21'/*!*/;
# at 1355
#180521 10:02:20 server id 3307101 end_log_pos 1520 CRC32 0x48415c32 Query thread_id=7 exec_time=0 error_code=0
use `test`/*!*/;
SET TIMESTAMP=1526868140/*!*/;
SET @@session.explicit_defaults_for_timestamp=0/*!*/;
create table zs1(a timestamp,b timestamp null default null,c timestamp null default null)
/*!*/;
# at 1520
#180521 10:05:36 server id 3307101 end_log_pos 1585 CRC32 0x749f7319 GTID last_committed=6 sequence_number=7 rbr_only=yes
/*!50718 SET TRANSACTION ISOLATION LEVEL READ COMMITTED*//*!*/;
SET @@SESSION.GTID_NEXT= 'd6a9d222-5282-11e8-bac7-080027691c44:22'/*!*/;
# at 1585
#180521 10:05:36 server id 3307101 end_log_pos 1657 CRC32 0x381adad5 Query thread_id=7 exec_time=0 error_code=0
SET TIMESTAMP=1526868336/*!*/;
BEGIN
/*!*/;
# at 1657
#180521 10:05:36 server id 3307101 end_log_pos 1708 CRC32 0x8b75b8d0 Table_map: `test`.`zs1` mapped to number 220
# at 1708
#180521 10:05:36 server id 3307101 end_log_pos 1748 CRC32 0x6f7e879b Write_rows: table id 220 flags: STMT_END_F
### INSERT INTO `test`.`zs1`
### SET
### @1=1526868336 /* TIMESTAMP(0) meta=0 nullable=0 is_null=0 */
### @2=NULL /* TIMESTAMP(0) meta=0 nullable=1 is_null=1 */
### @3=NULL /* TIMESTAMP(0) meta=0 nullable=1 is_null=1 */
# at 1748
#180521 10:05:36 server id 3307101 end_log_pos 1779 CRC32 0x8f7b45df Xid = 74
COMMIT/*!*/;
# at 1779
#180521 10:06:01 server id 3307101 end_log_pos 1844 CRC32 0x0857208f GTID last_committed=7 sequence_number=8 rbr_only=yes
/*!50718 SET TRANSACTION ISOLATION LEVEL READ COMMITTED*//*!*/;
SET @@SESSION.GTID_NEXT= 'd6a9d222-5282-11e8-bac7-080027691c44:23'/*!*/;
# at 1844
#180521 10:06:01 server id 3307101 end_log_pos 1916 CRC32 0xf8b57357 Query thread_id=7 exec_time=0 error_code=0
SET TIMESTAMP=1526868361/*!*/;
BEGIN
/*!*/;
# at 1916
#180521 10:06:01 server id 3307101 end_log_pos 1967 CRC32 0x71f69634 Table_map: `test`.`zs1` mapped to number 220
# at 1967
#180521 10:06:01 server id 3307101 end_log_pos 2007 CRC32 0x8398dbd6 Write_rows: table id 220 flags: STMT_END_F
### INSERT INTO `test`.`zs1`
### SET
### @1=1526868361 /* TIMESTAMP(0) meta=0 nullable=0 is_null=0 */
### @2=NULL /* TIMESTAMP(0) meta=0 nullable=1 is_null=1 */
### @3=NULL /* TIMESTAMP(0) meta=0 nullable=1 is_null=1 */
# at 2007
#180521 10:06:01 server id 3307101 end_log_pos 2038 CRC32 0xae8d3064 Xid = 77
COMMIT/*!*/;
# at 2038
#180521 10:06:02 server id 3307101 end_log_pos 2103 CRC32 0x50fdabc1 GTID last_committed=8 sequence_number=9 rbr_only=yes
/*!50718 SET TRANSACTION ISOLATION LEVEL READ COMMITTED*//*!*/;
SET @@SESSION.GTID_NEXT= 'd6a9d222-5282-11e8-bac7-080027691c44:24'/*!*/;
# at 2103
#180521 10:06:02 server id 3307101 end_log_pos 2175 CRC32 0x38a21fb3 Query thread_id=7 exec_time=0 error_code=0
SET TIMESTAMP=1526868362/*!*/;
BEGIN
/*!*/;
# at 2175
#180521 10:06:02 server id 3307101 end_log_pos 2226 CRC32 0x4a1b7b27 Table_map: `test`.`zs1` mapped to number 220
# at 2226
#180521 10:06:02 server id 3307101 end_log_pos 2266 CRC32 0x397de1b3 Write_rows: table id 220 flags: STMT_END_F
### INSERT INTO `test`.`zs1`
### SET
### @1=1526868362 /* TIMESTAMP(0) meta=0 nullable=0 is_null=0 */
### @2=NULL /* TIMESTAMP(0) meta=0 nullable=1 is_null=1 */
### @3=NULL /* TIMESTAMP(0) meta=0 nullable=1 is_null=1 */
# at 2266
#180521 10:06:02 server id 3307101 end_log_pos 2297 CRC32 0xe2727b87 Xid = 78
COMMIT/*!*/;
# at 2297
#180521 10:06:03 server id 3307101 end_log_pos 2362 CRC32 0x3cadd4ea GTID last_committed=9 sequence_number=10 rbr_only=yes
/*!50718 SET TRANSACTION ISOLATION LEVEL READ COMMITTED*//*!*/;
SET @@SESSION.GTID_NEXT= 'd6a9d222-5282-11e8-bac7-080027691c44:25'/*!*/;
# at 2362
#180521 10:06:03 server id 3307101 end_log_pos 2434 CRC32 0x06a0be65 Query thread_id=7 exec_time=0 error_code=0
SET TIMESTAMP=1526868363/*!*/;
BEGIN
/*!*/;
# at 2434
#180521 10:06:03 server id 3307101 end_log_pos 2485 CRC32 0xea1f5733 Table_map: `test`.`zs1` mapped to number 220
# at 2485
#180521 10:06:03 server id 3307101 end_log_pos 2525 CRC32 0xba9bf9de Write_rows: table id 220 flags: STMT_END_F
### INSERT INTO `test`.`zs1`
### SET
### @1=1526868363 /* TIMESTAMP(0) meta=0 nullable=0 is_null=0 */
### @2=NULL /* TIMESTAMP(0) meta=0 nullable=1 is_null=1 */
### @3=NULL /* TIMESTAMP(0) meta=0 nullable=1 is_null=1 */
# at 2525
#180521 10:06:03 server id 3307101 end_log_pos 2556 CRC32 0x1961d7b0 Xid = 79
COMMIT/*!*/;
# at 2556
#180521 10:09:00 server id 3307101 end_log_pos 2621 CRC32 0xe802a496 GTID last_committed=10 sequence_number=11 rbr_only=no
SET @@SESSION.GTID_NEXT= 'd6a9d222-5282-11e8-bac7-080027691c44:26'/*!*/;
# at 2621
#180521 10:09:00 server id 3307101 end_log_pos 2712 CRC32 0x1b99ba5c Query thread_id=7 exec_time=0 error_code=0
SET TIMESTAMP=1526868540/*!*/;
flush privileges
/*!*/;
mysqlbinlog: File '/root/mysqlbinlog21.log' not found (Errcode: 2 - No such file or directory)
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*/;

MYSQL binlog 日志内容查看的更多相关文章

  1. Mysql Binlog日志详解

    一.Mysql Binlog格式介绍       Mysql binlog日志有三种格式,分别为Statement,MiXED,以及ROW! 1.Statement:每一条会修改数据的sql都会记录在 ...

  2. MYSQL启用日志,查看日志,利用mysqlbinlog工具恢复MySQL数据库【转载】

    转自 MYSQL启用日志,查看日志,利用mysqlbinlog工具恢复MySQL数据库 - _安静 - 博客园http://www.cnblogs.com/xionghui/archive/2012/ ...

  3. 删除MySQL binlog日志的方法

    对于比较繁忙的OLTP(在线事务处理)系统,由于每天生成日志量大,这些日志如果长时间不清除,将会对磁盘空间带来很大的浪费.因此,定期删除日志是DBA维护MySQL数据库的一个重要工作内容.下面跟大家分 ...

  4. MySQL binlog日志操作详解

    MySQL的二进制日志可以说是MySQL最重要的日志了,它记录了所有的DDL和DML(除了数据查询语句)语句,以事件形式记录,还包含语句所执行的消耗的时间,MySQL的二进制日志是事务安全型的. bi ...

  5. MySQL binlog日志三种模式选择及配置

    在认识binlog日志三种模式前,先了解一下解析binlog日志的命令工mysqlbinlog.mysqlbinlog工具的作用是解析mysql的二进制binlog日志内容,把二进制日志解析成可以在M ...

  6. MySQL - binlog日志简介及设置

    基本概念 binlog是Mysql sever层维护的一种二进制日志,与innodb引擎中的redo/undo log是完全不同的日志:其主要是用来记录对mysql数据更新或潜在发生更新的SQL语句, ...

  7. 看数据库的文件大小 MySQL Binlog日志的生成和清理规则

    小结: 1.避免并行大大事务对磁盘.内存的消耗: MySQL数据文件导致实例空间满的解决办法_空间/内存_常见问题_云数据库 RDS 版-阿里云 https://help.aliyun.com/kno ...

  8. 【转载】mysql binlog日志自动清理及手动删除

    说明:当开启mysql数据库主从时,会产生大量如mysql-bin.00000* log的文件,这会大量耗费您的硬盘空间.mysql-bin.000001mysql-bin.000002mysql-b ...

  9. mysql binlog日志自动清理及手动删除

    说明:当开启mysql数据库主从时,会产生大量如mysql-bin.00000* log的文件,这会大量耗费您的硬盘空间.mysql-bin.000001mysql-bin.000002mysql-b ...

随机推荐

  1. js 预加载图片image()函数

    创建一个Image对象:var a=new Image();    定义Image对象的src: a.src=”xxx.gif”;    这样做就相当于给浏览器缓存了一张图片. 图像对象: 建立图像对 ...

  2. [Swift]二进制、八进制、十进制、十六进制之间的转换

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  3. 2. Add Two Numbers[M]两数相加

    题目 You are given two non-empty linked lists representing two non-negative integers. The digits are s ...

  4. 案例分析:大数据平台技术方案及案例(ppt)

    大数据平台是为了计算,现今社会所产生的越来越大的数据量,以存储.运算.展现作为目的的平台.大数据技术是指从各种各样类型的数据中,快速获得有价值信息的能力.适用于大数据的技术,包括大规模并行处理(MPP ...

  5. Java Servlet 配置

    图片太大,可以右键另存再查看,也可以鼠标点击拖置一下,用浏览器单独承载放大查看.

  6. mysql面试几个问题

    1.为什么InnoDB表最好要有自增列做主键? InnoDB引擎表是基于B+树的索引组织表(IOT) 关于B+树 (图片来源于网上) B+ 树的特点: a.所有关键字都出现在叶子结点的链表中(稠密索引 ...

  7. SQL基本语句:2.基本表

    SQL基本表的增删改

  8. Comparison of programming languages

    The following table compares general and technical information for a selection of commonly used prog ...

  9. 页面定制CSS代码初探(四):cnblogs使用Github引用样式

    前言 对于用惯了Github的人来说,眼里的引用应该是这样的 "Talk is cheap. Show me the code" -- Linus Torvalds 然而实际上cn ...

  10. C IO programming test code

    #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl ...