溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

主從復(fù)制中忽略庫(kù)的參數(shù)

發(fā)布時(shí)間:2020-05-01 12:03:28 來源:網(wǎng)絡(luò) 閱讀:1404 作者:qhd2004 欄目:MySQL數(shù)據(jù)庫(kù)

replicate-ignore-db

在slave服務(wù)器上設(shè)置 replicate-ignore-db = test(my.conf中設(shè)置)


在master上如下執(zhí)行

use test

delete from moedb.moe_userinfo where id=3;  slave上此語(yǔ)句不執(zhí)行


replicate_do_db

如在slave服務(wù)器上設(shè)置 replicate_do_db = test(my.conf中設(shè)置)


在master上如下執(zhí)行

use moedb

insert into test.moe(id,name) values (1,'moe');  slave上此語(yǔ)句不執(zhí)行


原因是設(shè)置replicate_ignore_db或replicate_do_db后,MySQL執(zhí)行sql前檢查的是當(dāng)前默認(rèn)數(shù)據(jù)庫(kù),所以跨庫(kù)更新語(yǔ)句在Slave上會(huì)被忽略。

可以在Slave上使用 replicate_wild_do_table 和 replicate_wild_ignore_table 來解決跨庫(kù)更新的問題,如:

replicate_wild_ignore_table=test.%

replicate_wild_do_table=test.%


如果是針對(duì)多個(gè)庫(kù),那每行一個(gè)庫(kù)名,例如,需要忽略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 選項(xiàng)是危險(xiǎn)的.

 

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.

 

我發(fā)現(xiàn)很多人通過 binlog-do-db, binlog-ignore-db, replicate-do-db 和 replicate-ignore-db 來過濾復(fù)制(某些數(shù)據(jù)庫(kù)), 盡管有些使用, 但是,在我看來,他們是危險(xiǎn)的,并且他們被濫用了. 對(duì)于很多的實(shí)例,有更安全的替換方案.

 

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.)

 

為什么危險(xiǎn)很簡(jiǎn)單: 他們并不像你想的那樣工作. 想象如下的場(chǎng)景: 你設(shè)置了 binlog-ignore-db = garbage, 所以 garbage數(shù)據(jù)庫(kù)(在slave上不存在這個(gè)數(shù)據(jù)庫(kù)) 中的數(shù)據(jù)不會(huì)被復(fù)制,(待會(huì)兒我再講這個(gè),如果你已經(jīng)發(fā)現(xiàn)問題了,不要急于到評(píng)論表單)

 

Now you do the following:

現(xiàn)在做下面的事情:

$ 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.

 

復(fù)制會(huì)broke2次, 第一次,因?yàn)?slave嘗試著去之西你給第一條語(yǔ)句,但是slave上并沒有這樣的表"garbage.junk" , 第二次, 隱含的, 因?yàn)?對(duì) production.users不會(huì)被 復(fù)制,因?yàn)?root帳號(hào)并沒有在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.

 

為什么? 因?yàn)?binlog-ignore-db 并不像你想的那樣執(zhí)行, 我之前說的, "在garbage數(shù)據(jù)庫(kù)中的數(shù)據(jù)不會(huì)被復(fù)制" 是錯(cuò)的, 實(shí)際上(數(shù)據(jù)庫(kù))并沒有這么做.事實(shí)上, 他是通過默認(rèn)的數(shù)據(jù)庫(kù)為“garbage" 的連接, 過濾二進(jìn)制的(SQL)語(yǔ)句日志的. 換句話說, 過濾不是基于 查詢的字符串的, 而實(shí)際于你used的數(shù)據(jù)庫(kù).

 

 

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.

 

其他我提到的配置選項(xiàng)也都類似. binlog-do-db 和 binlog-ignore-db 語(yǔ)句是特別危險(xiǎn)的,因?yàn)樗麄儗⒄Z(yǔ)句寫入了二進(jìn)制日志. 意味著你不能使用二進(jìn)制日志從備份恢復(fù)指定時(shí)間的數(shù)據(jù).

 

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

 

在嚴(yán)格控制的環(huán)境中, 這些選項(xiàng)是很有用的,但是我不會(huì)談?wù)撨@些(這些包含在我們的書中),

 

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上配置過濾, 使用基于查詢中真正涉及到的表的選項(xiàng), 這些是: replicate-wild-* 選項(xiàng), 例如, 避免復(fù)制 garbage數(shù)據(jù)庫(kù)中的數(shù)據(jù)的安全的方案是 配置: replicate-wild-ignore-table=garbage.%. 這樣做仍然有一些特殊的情況, 不能正常工作,但可以在更多的情況下正常工作,并且會(huì)遇到更少的意外 (gotchas).

 

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

如果你有些疑惑了,你應(yīng)該去讀一讀手冊(cè)上的復(fù)制規(guī)則一節(jié),直到你真正明白為止.

 

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


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI