replicate-ignore-db

在slave服务器上设置 replicate-ignore-db = test(my.conf中设置)

在master上如下执行

use test

delete from moedb.moe_userinfo where id=3;  slave上此语句不执行

replicate_do_db

如在slave服务器上设置 replicate_do_db = test(my.conf中设置)

在master上如下执行

use moedb

insert into test.moe(id,name) values (1,'moe');  slave上此语句不执行

原因是设置replicate_ignore_db或replicate_do_db后,MySQL执行sql前检查的是当前默认数据库,所以跨库更新语句在Slave上会被忽略。

可以在Slave上使用 replicate_wild_do_table 和 replicate_wild_ignore_table 来解决跨库更新的问题,如:

replicate_wild_ignore_table=test.%

replicate_wild_do_table=test.%

如果是针对多个库,那每行一个库名,例如,需要忽略test、mysql,如下:

replicate_wild_ignore_table=test.%

replicate_wild_ignore_table=mysql.%

参考如下:

原文: http://www.mysqlperformanceblog.com/2009/05/14/why-mysqls-binlog-do-db-option-is-dangerous/

作者: Baron Schwartz

Why MySQL’s binlog-do-db option is dangerous

为什么 MySQL的 binlog-do-db 选项是危险的.

I see a lot of people filtering replication with binlog-do-db, binlog-ignore-db, replicate-do-db, and replicate-ignore-db. Although there are uses for these, they are dangerous and in my opinion, they are overused. For many cases, there's a safer alternative.

我发现很多人通过 binlog-do-db, binlog-ignore-db, replicate-do-db 和 replicate-ignore-db 来过滤复制(某些数据库), 尽管有些使用, 但是,在我看来,他们是危险的,并且他们被滥用了. 对于很多的实例,有更安全的替换方案.

The danger is simple: they don't work the way you think they do. Consider the following scenario: you set binlog-ignore-db to "garbage" so data in the garbage database (which doesn't exist on the slave) isn't replicated. (I'll come back to this in a second, so if you already see the problem, don't rush to the comment form.)

为什么危险很简单: 他们并不像你想的那样工作. 想象如下的场景: 你设置了 binlog-ignore-db = garbage, 所以 garbage数据库(在slave上不存在这个数据库) 中的数据不会被复制,(待会儿我再讲这个,如果你已经发现问题了,不要急于到评论表单)

Now you do the following:

现在做下面的事情:

$ mysql
mysql> delete from garbage.junk; 
mysql> use garbage;
mysql> update production.users set disabled = 1 where user = "root";

You just broke replication, twice. Once, because your slave is going to execute the first query and there's no such table "garbage.junk" on the slave. The second time, silently, because the update to production.users isn't replicated, so now the root user isn't disabled on the slave.

复制会broke2次, 第一次,因为 slave尝试着去之西你给第一条语句,但是slave上并没有这样的表"garbage.junk" , 第二次, 隐含的, 因为 对 production.users不会被 复制,因为 root帐号并没有在slave上被禁用掉.

Why? Because binlog-ignore-db doesn't do what you think. The phrase I used earlier, "data in the garbage database isn't replicated," is a fallacy. That's not what it does. In fact, it filters out binary logging for statements issued from connections whose default database is "garbage." In other words, filtering is not based on the contents of the query -- it is based on what database you USE.

为什么? 因为 binlog-ignore-db 并不像你想的那样执行, 我之前说的, "在garbage数据库中的数据不会被复制" 是错的, 实际上(数据库)并没有这么做.事实上, 他是通过默认的数据库为“garbage" 的连接, 过滤二进制的(SQL)语句日志的. 换句话说, 过滤不是基于 查询的字符串的, 而实际于你used的数据库.

The other configuration options I mentioned work similarly. The binlog-do-db and binlog-ignore-db statements are particularly dangerous because they keep statements from ever being written to the binary log, which means you can't use the binary log for point-in-time recovery of your data from a backup.

其他我提到的配置选项也都类似. binlog-do-db 和 binlog-ignore-db 语句是特别危险的,因为他们将语句写入了二进制日志. 意味着你不能使用二进制日志从备份恢复指定时间的数据.

In a carefully controlled environment, these options can have benefits, but I won't talk about that here. (We covered that in our book.)

在严格控制的环境中, 这些选项是很有用的,但是我不会谈论这些(这些包含在我们的书中),

The safer alternative is to configure filters on the slave, with options that actually operate on the tables mentioned in the query itself. These are replicate-wild-* options. For example, the safer way to avoid replicating data in the garbage database is to configure replicate-wild-ignore-table=garbage.%. There are still edge cases where that won't work, but it works in more cases and has fewer gotchas.

安全的替换方案是 在 slave上配置过滤, 使用基于查询中真正涉及到的表的选项, 这些是: replicate-wild-* 选项, 例如, 避免复制 garbage数据库中的数据的安全的方案是 配置: replicate-wild-ignore-table=garbage.%. 这样做仍然有一些特殊的情况, 不能正常工作,但可以在更多的情况下正常工作,并且会遇到更少的意外 (gotchas).

If you are confused, you should read the replication rules section of the manual until you know it by heart

如果你有些疑惑了,你应该去读一读手册上的复制规则一节,直到你真正明白为止.

Refer from http://www.mysqlperformanceblog.com/2009/05/14/why-mysqls-binlog-do-db-option-is-dangerous

转载于:https://blog.51cto.com/qhd2004/1948506

主从复制中忽略库的参数相关推荐

  1. 主从复制中从库Last_SQL_Errno: 1062 错误

    解决办法: 修改从库的mysql的配置文件,/etc/my.cnf,在[mysqld]下面添加一行 slave_skip_errors = 1062 :wq 然后重启mysql服务 转载于:https ...

  2. VC++中忽略所有默认库纯Win32 API编译及链接 - 计算机软件编程 - Wangye's Space

    原始链接: VC++中忽略所有默认库纯Win32 API编译及链接 - 计算机软件编程 - Wangye's Space 我们在用VC++编写Windows程序的时候可能会发现一般可执行体(.EXE) ...

  3. python get方法列表参数_python中requests库get方法带参数请求

    起因是想爬五等分的花嫁的漫画.这是其中的一个坑 先上代码 data={ 'cid':567464, 'page':, 'key':'', 'language':1, 'gtk':6, '_cid':5 ...

  4. MySQL主从复制中的“show slave status”详细含义

    MySQL主从复制中的"show slave status"详细含义 正常状态的信息 *************************** 1. row ************ ...

  5. python 颜色_如何使用python中matplotlib库分析图像颜色

    用代码分析图像可能很困难.你如何使代码"理解"图像的上下文? 通常,使用AI分析图像的第一步 是找到主要颜色.在如何使用python中matplotlib库分析图像颜色中,我们将使 ...

  6. Linux中命令选项及参数简介

    登录Linux后,我们就可以在#或$符后面去输入命令,有的时候命令后面还会跟着"选项"(英文options)或"参数"(英文arguments).即Linux中 ...

  7. Python 中MNE库去伪迹(ICA)案例的逐句解析

    本文是在阅读博主zhoudapeng01的文章Python 中MNE库去伪迹(ICA)_zhoudapeng01的博客-CSDN博客_ica mne后做的一个翻译工作. 主要介绍的还是ICA,需要了解 ...

  8. Python中BeautifulSoup库的用法

    BeautifulSoup简介 Beautiful Soup是python的一个库,最主要的功能是从网页抓取数据.官方解释如下: Beautiful Soup提供一些简单的.python式的函数用来处 ...

  9. python时间函数报错_python3中datetime库,time库以及pandas中的时间函数区别与详解...

    1介绍datetime库之前 我们先比较下time库和datetime库的区别 先说下time 在 Python 文档里,time是归类在Generic Operating System Servic ...

最新文章

  1. matlab怎么跑.cpp程序,MATLAB编译cpp文件
  2. java 队列的数组_java使用数组实现队列
  3. websocket学习笔记
  4. Deep Learning运行所需的硬件配置(转)
  5. Angular属性型指令
  6. 21.和和instance of
  7. 一款不错的开源 Laravel 后台面板/CMS系统 —— LaraAdmin
  8. mac安装thrift
  9. Ajax异步刷新,测试用户名是否被注册
  10. 单点登录原理与简单实现
  11. Linux重启tomcat服务
  12. Stripe国际支付简介及API对接
  13. 解决 uniapp 打包次数限制
  14. 堆排序(Heapsort)-全网最详细
  15. xxx.so has text relocations. This is wasting memory and is a security risk. Please fix
  16. 微信小程序校园生活小助手+后台管理系统前后分离VUE
  17. 计蒜客T1003输出字符菱形
  18. 【PyTorch】切记:GeForce RTX 3090 显卡仅支持 CUDA 11 以上的版本!
  19. 转:什么是 CRA ?
  20. Win10开启telnet功能

热门文章

  1. linux python开发环境sql数据迁移到mysql_运用Python语言编写获取Linux基本系统信息(三):Python与数据库编程,把获取的信息存入数据库...
  2. c语言宏定义_C语言宏定义
  3. 获取当前登录的QQ号码
  4. CentOS离线安装gcc4.8.2 + 并安装网卡驱动
  5. linux消息队列的内核限制
  6. #define与enum,你不知道的那些事
  7. 使用gorilla/mux增强Go HTTP服务器的路由能力
  8. Java网络编程-1
  9. springboot整合Apollo
  10. vue2.0 keep-alive最佳实践