群里看到有同学提问,多瞅了眼

[root@mysql55 mysql]# mysqlbinlog --no-defaults -vv --base64-output=decode-rows mysql-bin. --skip-gtids
...
# at
# :: server id end_log_pos CRC32 0x7e37d2ec Query thread_id= exec_time= error_code=
SET TIMESTAMP=/*!*/;
insert into kk.kk values()
/*!*/;
# at [root@mysql55 mysql]# mysqlbinlog --no-defaults -vv --base64-output=decode-rows mysql-bin. --skip-gtids -d kk
...
# at
# at
# :: server id end_log_pos CRC32 0x3c5ea8e8 Xid =
COMMIT/*!*/;

原意是想筛选指定数据库下的entries,指定-d解析发现3370~3465之间的entries丢失
首先binlog中记录了insert into kk.kk values(7),可以肯定当时binlog_format=statement;使用-d参数后insert语句消失,怀疑日志格式引起异常
自己针对statement、row格式测试一番,然后解析binlog基本确定上述问题的原因
1、日志格式是 binlog_format='statement'
2、insert into kk.kk values(7) 这个语句不是在kk库下执行
后来那位同学私聊我,确认了上面的情况(・ω・)
官方文档对mysqlbinlog --database已经解释的十分清楚

https://dev.mysql.com/doc/refman/5.7/en/mysqlbinlog.html
--database=db_name, -d db_name
This option causes mysqlbinlog to output entries from the binary log (local log only) that occur while db_name is been selected as the default database by USE.
The --database option for mysqlbinlog is similar to the --binlog-do-db option for mysqld, but can be used to specify only one database. If --database is given multiple times, only the last instance is used.
The effects of this option depend on whether the statement-based or row-based logging format is in use, in the same way that the effects of --binlog-do-db depend on whether statement-based or row-based logging is in use.
Statement-based logging.The --database option works as follows:
• While db_name is the default database, statements are output whether they modify tables in db_name or a different database.
• Unless db_name is selected as the default database, statements are not output, even if they modify tables in db_name.
• There is an exception for CREATE DATABASE, ALTER DATABASE, and DROP DATABASE. The database being created, altered, or dropped is considered to be the default database when determining whether to output the statement.
Suppose that the binary log was created by executing these statements using statement-based-logging:

INSERT INTO test.t1 (i) VALUES(100);
INSERT INTO db2.t2 (j) VALUES(200);
USE test;
INSERT INTO test.t1 (i) VALUES(101);
INSERT INTO t1 (i) VALUES(102);
INSERT INTO db2.t2 (j) VALUES(201);
USE db2;
INSERT INTO test.t1 (i) VALUES(103);
INSERT INTO db2.t2 (j) VALUES(202);
INSERT INTO t2 (j) VALUES(203);

mysqlbinlog --database=test does not output the first two INSERT statements because there is no default database. It outputs the three INSERT statements following USE test, but not the three INSERT statements following USE db2.
mysqlbinlog --database=db2 does not output the first two INSERT statements because there is no default database. It does not output the three INSERT statements following USE test, but does output the three INSERT statements following USE db2.
Row-based logging.mysqlbinlog outputs only entries that change tables belonging to db_name.The default database has no effect on this. Suppose that the binary log just described was created using row-based logging rather than statement-based logging. mysqlbinlog --database=test outputs only those entries that modify t1 in the test database, regardless of whether USE was issued or what the default database is.
If a server is running with binlog_format set to MIXED and you want it to be possible to use mysqlbinlog with the --database option, you must ensure that tables that are modified are in the database selected by USE. (In particular, no cross-database updates should be used.)

Statement格式:use db_name后的语句(操作db_name、其他库),全部能被mysqlbinlog --database=db_name解析出来;use other_db后面的语句,哪怕是操作db_name下的对象也不能被mysqlbinlog --database=db_name解析出来;create/alter/drop database db_name能被解析出来。
Row格式:只要操作db_name下的对象,就能被mysqlbinlog --database=db_name解析出来,与语句在哪个db执行无关。
开篇的那个问题应该如何避免呢?使用Row-based logging~
开始接触MySQL复制时,看到很多说binlog-do-db/binlog-ignore-db是危险的(跨库操作),当时就傻傻的死记下来。很长时间过后发现那些文章根本就没提及binlog_format,根本就不能一概而论~没有环境说明的测试都是扯蛋,文章说的再好也不及用实验来验证~

为什么mysqlbinlog --database选项不起作用的更多相关文章

  1. Linux系统源码安装软件过程中configure选项-prefix的作用

    在linux和unix环境中,源码安装是最常用的软件安装方式,一些软件出了提供源码外,也提供各种发行版的二进制安装包(如基于redhat包管理工具的rpm包),但强烈建议使用源码安装方式. 在linu ...

  2. Linux源码安装过程中选项—prefix的作用

    源码的安装一般由3个步骤组成:配置(configure).编译(make).安装(make install),具体的安装方法一般作者都会给出文档,这里主要讨论配置(configure).Configu ...

  3. mysql中/*!40000 DROP DATABASE IF EXISTS `top_server`*/;这中注释有什么作用?

    需求描述: 今天在进行mysqldump实验,使用--add-drop-databases参数,于是在生成的SQL文件中,就出现了. /*!40000 DROP DATABASE IF EXISTS ...

  4. 使用mysqlbinlog查看二进制日志

    (一)mysqlbinlog工具介绍 binlog类型是二进制的,也就意味着我们没法直接打开看,MySQL提供了mysqlbinlog来查看二进制日志,该工具类似于Oracle的logminer.my ...

  5. 答:SQLServer DBA 三十问之二:系统DB有哪些,都有什么作用,需不需要做备份,为什么;损坏了如何做还原(主要是master库)

    2. 系统DB有哪些,都有什么作用,需不需要做备份,为什么:损坏了如何做还原(主要是master库): master:它包含一个系统表集合,是整个实例的中央存储库,维护登录账户,其他数据库,文件分布, ...

  6. mysqlbinlog 用法

    操作命令: show binlog events in 'binlog.000016' limit 10; reset master 删除所有的二进制日志 flush logs  产生一个新的binl ...

  7. mysqlbinlog恢复数据

    操作命令: 复制代码代码如下: show binlog events in 'mysql-bin.000016' limit 10; reset master 删除所有的二进制日志flush logs ...

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

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

  9. 超级有用的15个mysqlbinlog命令

    在MySQL或MariaDB中,任意时间对数据库所做的修改,都会被记录到日志文件中.例如,当你添加了一个新的表,或者更新了一条数据,这些事件都会被存储到二进制日志文件中.二进制日志文件在MySQL主从 ...

随机推荐

  1. Symfony中Doctrine对应的Mongodb数据类型 data type

    1. hash 就是 json对象 2. collection 就是 数组 3. 若要知道如何使用referenceOne, referenceMany, embbedDocument等 主要查看: ...

  2. SQL邮件服务(解决各种疑难杂症)+案例 + 使用SQLserver 邮件系统发送SQL代理作业执行警告

    首先你需要知道你要做的几部: 1 每个数据库都有自己的 SERVICE BROKER 很多SQL SERVER内部服务依赖它 2 启动 SERVICE BROKER 需要 1 STOP 你的 SQL  ...

  3. 20135323符运锦----第三周:构建一个简单的Linux系统MenuOS

    相关知识点 1.arch目录 占据相当庞大的空间,X86目录下代码需要重点关注. 2.init目录 内核启动的相关代码基本都在此目录下,内含MAIN.C,文件中START_KERNEL是整个LINUX ...

  4. C++:同名隐藏和赋值兼容规则

    一.同名隐藏 同名隐藏,即在C++的继承中,只要子类的函数名和父类的函数名相同,子类中的函数将会隐藏所有父类中和子类的成员函数同名的函数 特别注意: 和函数之间的重载不同,这里只要求函数的名字相同,而 ...

  5. Photo Cleaner -- proposed by Wei Zhang

    Need想必大家都有用手机或相机记录生活的习惯吧!在旅途中,驴友们见到美丽的风景,往往激动地咔嚓一下拍张照记录下来.完事后发现角度不太好,于是又咔嚓一下……不知不觉中一下照了好多,然而真正需要的只是那 ...

  6. Orchard是如何运行的

    建立一个CMS网站(内容管理系统)是不同于建立一个普通的web站点:它更像是建立一个应用程序容器. 设计这样一个系统时,必须建立一流的可扩展性功能.这必需是一个非常开放式的构架,但是一个开放性的系统可 ...

  7. chrome-extension & inject.js

    chrome-extension & inject.js chrome-extension://gppongmhjkpfnbhagpmjfkannfbllamg/js/inject.js in ...

  8. 前端开发【第6篇:JavaScript客户端(浏览器)】

    Web浏览器中的JavaScript 客户端JavaScript时间线 1.Web浏览器创建Document对象,并且开始解析web页面,解析HTML元素和它门的文本内容后添加Element对象和Te ...

  9. MySQL 5.7 GA 新特性

    转载自: http://www.chinaxing.org/articles/Database/2015/10/23/2015-10-22-mysql-5.7.html sys-schema http ...

  10. MT【194】又见和式变换

    (2007浙江省赛B卷最后一题)设$\sum\limits_{i=1}^{n}{x_i}=1,x_i>0,$求证:$n\sum\limits_{i=1}^n{x_i^2}-\sum\limits ...