mysql binlog如何查看(MySQL binlog_ignore_db 参数的具体使用)
mysql binlog如何查看
MySQL binlog_ignore_db 参数的具体使用前言:
经过前面文章学习,我们知道 binlog 会记录数据库所有执行的 DDL 和 DML 语句(除了数据查询语句select、show等)。注意默认情况下会记录所有库的操作,那么如果我们有另类需求,比如说只让某个库记录 binglog 或排除某个库记录 binlog ,是否支持此类需求呢?本篇文章我们一起来看下。
1. binlog_do_db 与 binlog_ignore_db
当数据库实例开启 binlog 时,我们执行 show master status 命令,会看到有 Binlog_Do_DB 与 Binlog_Ignore_DB 选项。
|
mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000009 | 282838 | | | | + ---------------+----------+--------------+------------------+-------------------+ |
默认情况下,这两个选项为空,那么这两个参数有何作用?是否如同其字面意思一个只让某个库记录 binglog 一个排除某个库记录 binlog 呢?笔者查阅官方文档,简单说明下这两个参数的作用:
- binlog_do_db:此参数表示只记录指定数据库的二进制日志,默认全部记录。
- binlog_ignore_db:此参数表示不记录指定的数据库的二进制日志。
这两个参数为互斥关系,一般只选择其一设置,只能在启动命令行中或配置文件中加入。指定多个数据库要分行写入,举例如下:
|
# 指定 db1 db2 记录binlog [mysqld] binlog_do_db = db1 binlog_do_db = db2 # 不让 db3 db4 记录binlog [mysqld] binlog_ignore_db = db3 binlog_ignore_db = db4 |
此外,这二者参数具体作用与否还与 binlog 格式有关系,在某些情况下 binlog 格式设置为 STATEMENT 或 ROW 会有不同的效果。在实际应用中 binlog_ignore_db 用途更广泛些,比如说某个库的数据不太重要,为了减轻服务器写入压力,我们可能不让该库记录 binlog 。网上也有文章说设置 binlog_ignore_db 会导致从库同步错误,那么设置该参数到底有什么效果呢,下面我们来具体实验下。
2. binlog_ignore_db 具体效果
首先说明下,我的测试数据库实例是 5.7.23 社区版本,共有 testdb、logdb 两个业务库,我们设置 logdb 不记录 binlog ,下面来具体实验下:
|
# binlog 为 ROW 格式 # 1.不使用 use db mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 154 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ mysql> select database (); + ------------+ | database () | + ------------+ | NULL | + ------------+ 1 row in set (0.00 sec) mysql> CREATE TABLE testdb.`test_tb1` ( id int , name varchar (30) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.06 sec) mysql> insert into testdb.test_tb1 values (1001, 'sdfde' ); Query OK, 1 row affected (0.01 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 653 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> CREATE TABLE logdb.`log_tb1` ( id int , name varchar (30) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.05 sec) mysql> insert into logdb.log_tb1 values (1001, 'sdfde' ); Query OK, 1 row affected (0.00 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 883 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ mysql> insert into logdb.log_tb1 values (1002, 'sdsdfde' ); Query OK, 1 row affected (0.01 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 883 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ mysql> alter table logdb.log_tb1 add column c3 varchar (20); Query OK, 0 rows affected (0.12 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 1070 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ # 结论:其他库记录正常 logdb库会记录DDL 不记录DML # 2.使用 use testdb跨库 mysql> use testdb; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select database (); + ------------+ | database () | + ------------+ | testdb | + ------------+ 1 row in set (0.00 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 1070 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> CREATE TABLE `test_tb2` ( id int , name varchar (30) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.05 sec) mysql> insert into test_tb2 values (1001, 'sdfde' ); Query OK, 1 row affected (0.04 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 1574 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> CREATE TABLE logdb.`log_tb2` ( id int , name varchar (30) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.05 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 1810 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> insert into logdb.log_tb2 values (1001, 'sdfde' ); Query OK, 1 row affected (0.01 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 1810 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) # 结论:同样logdb库会记录DDL 不记录DML # 3.使用 use logdb跨库 mysql> use logdb; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select database (); + ------------+ | database () | + ------------+ | logdb | + ------------+ 1 row in set (0.00 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 1810 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> CREATE TABLE testdb.`test_tb3` ( id int , name varchar (30) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.23 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 1810 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> insert into testdb.test_tb3 values (1001, 'sdfde' ); Query OK, 1 row affected (0.02 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 2081 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> CREATE TABLE `log_tb3` ( id int , name varchar (30) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.05 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 2081 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> insert into log_tb3 values (1001, 'sdfde' ); Query OK, 1 row affected (0.02 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 2081 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) # 结论:logdb都不记录 同时不记录其他库的DDL # 4.每次操作都进入此库 不跨库 mysql> use testdb; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 2081 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> CREATE TABLE `test_tb4` ( id int , name varchar (30) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.05 sec) mysql> insert into test_tb4 values (1001, 'sdfde' ); Query OK, 1 row affected (0.01 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 2585 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> use logdb; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> CREATE TABLE `log_tb4` ( id int , name varchar (30) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.04 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 2585 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> insert into log_tb4 values (1001, 'sdfde' ); Query OK, 1 row affected (0.01 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 2585 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) # 结论:其他库全部记录 logdb全不记录 |
同样的,将 binlog 格式设置为 STATEMENT ,再次进行测试,这里不再赘述测试过程,总结下 STATEMENT 格式下的实验结果:
- 未选择任何数据库进行操作,所有都会记录。
- 选择testdb,对testdb和logdb分别进行操作,所有库都会记录。
- 选择logdb,对testdb和logdb分别进行操作,所有库都不会记录。
- 选择某个库并只对当前库进行操作,则记录正常,不会记录logdb。
看了这么多实验数据,你是否眼花缭乱了呢,下面我们以思维导图的形式总结如下:
这么看来 binlog_ignore_db 参数的效果确实和诸多因素有关,特别是有从库的情况下,主库要特别小心使用此参数,很容易产生主从同步错误。不过,按照严格标准只对当前数据库进行操作,则不会产生问题。这也告诉我们要严格按照标准来,只赋予业务账号某个单库的权限,也能避免各种问题发生。
总结:
不清楚各位读者是否对这种介绍参数的文章感兴趣呢?可能这些是数据库运维人员比较关注的吧。本篇文章主要介绍关于 binlog 的 binlog_ignore_db 参数的具体作用,可能本篇文章实验环境还不够考虑周全,有兴趣的同学可以参考下官方文档,有助于对该参数有更深入的了解。
以上就是MySQL binlog参数的使用的详细内容,更多关于MySQL binlog参数的资料请关注开心学习网其它相关文章!
原文链接:https://mp.weixin.qq.com/s/Xwwr1HJKRglNH9V-Ddihlg
- centos7离线安装mysql5.7(CentOS7.5 安装MySql的教程)
- MySQL中TIMESTAMP和DATETIME
- mysql8.0安装版安装详细教程(mysql 8.0.24版本安装配置方法图文教程)
- mysql操作时间的函数(一篇文章搞定Mysql日期时间函数)
- mysql触发器怎么添加(MySQL触发器的使用场景及方法实例)
- mysql拼接多字段作为查询条件(Mysql 实现字段拼接的三个函数)
- mysql子查询用法(MySQL 子查询和分组查询)
- apache2.4支持php5.5吗(WINDOWS下php5.2.4+mysql6.0+apache2.2.4+ZendOptimizer-3.3.0配置)
- mysql添加注释视图(mysql创建表添加字段注释的实现方法)
- mysql创建数据库基本指令(MySql 新建用户与数据库的实际操作步骤)
- mysql中FIND_IN_SET函数
- mysql8.0.19.0正确安装图解(MySQL 8.0.23 主要更新一览新特征解读)
- navicat连接mysql报错(解决Navicat Premium 连接 MySQL 8.0 报错"1251"的问题分析)
- mysql的常见优化(详解GaussDB for MySQL性能优化)
- Mysql中CONCAT、CONCAT_WS字符串拼接函数
- mysql存储json的方式(MySQL中查询json格式的字段实例详解)
- 文明6金币太少怎么办 文明6无限刷钱教程(文明6金币太少怎么办)
- 开国中将,王牌军63军首任政委,两个连襟一个上将一个少将传为佳话(王牌军63军首任政委)
- 臭名昭著的731部队最高负责人 石井四郎(臭名昭著的731部队最高负责人)
- 王牌部队,你看的剧情我看的时尚(你看的剧情我看的时尚)
- 被鉴定的古董价值300万 当心,你可能遇到诈骗了(被鉴定的古董价值300万)
- 英语难学吗(初中英语难学吗)
热门推荐
- sqlserver查看某个库所有表(SQL Server怎么找出一个表包含的页信息Page)
- dedecms是静态吗(dedecms全站伪静态的实现方法及注意事项)
- python函数使用方法高级用法(Python函数的参数常见分类与用法实例详解)
- css3怎么改成3d(灵活运用CSS3特性绘制简易版围棋效果)
- linux怎么搭建nfs(通过案例深入解析linux NFS机制)
- dedecms后台内链如何制作(DedeCMS系统TAG标签和分页伪静态设置教程的实现)
- ftp服务器设置好无法访问(登陆FTP服务器feat命令错误的解决方法[登陆后不能得到文件列表的解决办法])
- linux下安装nginx常见问题(Linux安装Nginx步骤详解)
- iframe嵌入页面高度自动适应
- linux系统登录mysql数据库(Linux手动部署远程的mysql数据库的方法详解)
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9