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

[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. 12.23daily_scrum

    今天大家的工作重心在调试过程中,以便及时地发现和解决在调试过程中出现的问题和漏洞,悬浮窗测试工作也已经展开,主要集中在边缘设计代码的测试部分,具体工作如下: 具体工作: 小组成员 今日任务 明日任务 ...

  2. 关于给C盘扩容以及动态磁盘

    2019.4.5 周五 磁盘分为基本磁盘和动态磁盘 基本磁盘转动态磁盘是很容易的 https://jingyan.baidu.com/article/59a015e3a3d504f7948865b1. ...

  3. Jmeter put 方法总结

    1.百度到很多关于jmeter put 方法的使用 ,但觉得都完全 下面我大致总结下 : >1.放入 url 中 如:www.*****.com?a=1&b=2 ; >2.放入到p ...

  4. Oracle 数据库执行 操作系统的命令

    1 Linux环境下面的处理 在sqlplus 里面 添加一个 ! 就可以执行 但是 因为Oracle 必须为非root用户 所以很多命令可能无法执行: 2. Windows 环境执行命令的方式 是在 ...

  5. 如何用Delphi开发网游外挂

    1.动作式,所谓动作式,就是指用API发命令给窗口或API控制鼠标.键盘等,使游戏里的人物进行流动或者攻击,最早以前的“石器”外挂就是这种方式.2.本地修改式,这种外挂跟传统上的一些游戏修改器没有两样 ...

  6. Vue项目部署问题及解决方案

    Vue项目部署问题及解决方案 Vue-Router 有两种模式,默认是 hash 模式,另外一种是 history 模式. hash:也就是地址栏里的 # 符号.比如 http://www.examp ...

  7. python中 除了if else def class 有作用域 其余没有作用域

    python中 除了if else def class 有作用域 其余没有作用域

  8. Java 8新特性之 Optional(八恶人-5)

    Oswaldo Mobray 莫博瑞·奥斯瓦尔多 “I‘m Oswaldo Mobray, the hangman in these parts.” “我是莫博瑞·奥斯瓦尔多,这片地区的绞刑官.” 一 ...

  9. Maven父子项目配置-多模块(multi-modules)结构

    Maven创建父子项目,这个项目指的是eclipse中的project,idea中的module.使用idea创建的话很简单,可以直接选择项目的父亲,这些网上有很多资料的. 这里说一下创建父子项目时, ...

  10. 【题解】 bzoj1597: [Usaco2008 Mar]土地购买 (动态规划+斜率优化)

    bzoj1597懒得复制,戳我戳我 Solution: 线性DP打牌\(+\)斜率优化 定义状态:\(dp[i]\)到了位置\(i\)最少花费 首先我们要发现,如果有一个小方块能被其他的大方块包围,其 ...