MySQL主從同步部分庫跨庫問題排查分析

MySQL主從同步部分庫跨庫問題排查分析

成都創(chuàng)新互聯(lián)公司是專業(yè)的延慶網(wǎng)站建設(shè)公司,延慶接單;提供網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計,網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進行延慶網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!

問題:使用復(fù)制是設(shè)置   Replicate_Do_DB參數(shù)發(fā)現(xiàn)跨庫操作時從庫數(shù)據(jù)不更新

 

1設(shè)置從庫的 replicate_do_db = test

2主庫的sql語句是跨庫的insert    在test7上插入數(shù)據(jù)到test.a的表上。

  use test7;

MySQL主從同步部分庫跨庫問題排查分析

3主庫數(shù)據(jù)更新后查看從庫信息發(fā)現(xiàn)數(shù)據(jù)并沒有插入

MySQL主從同步部分庫跨庫問題排查分析

4原因是mysql在執(zhí)行sql前檢查的當前默認庫,所以跨庫的sql語句不會被執(zhí)行。

 

解決方案:

 

1使用參數(shù)  replicate-wild-ignore-table =test.%

主庫插入數(shù)據(jù)

 

MySQL主從同步部分庫跨庫問題排查分析

從庫查看數(shù)據(jù) 

MySQL主從同步部分庫跨庫問題排查分析

 

----------2使用復(fù)制的組合過濾規(guī)則:replicate-do-db和replicate-do-table兩個參數(shù)的過濾規(guī)則-------------暫時測試失敗

 

參數(shù)說明

Replicate_Do_DB :

The effects of this option depend on whether statement-based or row-based replication is in use.

Statement-based replication.  Tell the slave SQL thread to restrict replication to statements where the default database (that is, the one selected by USE) is db_name. To specify more than one database, use this option multiple times, once for each database; however, doing so does not replicate cross-database statements such asUPDATE some_db.some_table SET foo='bar' while a different database (or no database) is selected.

Warning

To specify multiple databases you must use multiple instances of this option. Because database names can contain commas, if you supply a comma separated list then the list will be treated as the name of a single database

· 

replicate-do-db =db_name 告訴從庫sql線程限制復(fù)制sql語句,只復(fù)制默認的數(shù)庫,多個數(shù)據(jù)庫可以使用","

· 

跨庫sql不被執(zhí)行的原因:“檢查默認的數(shù)據(jù)庫”行為是從sql語句中很難得知是否復(fù)制。sql進程檢查的只是默認的數(shù)據(jù)庫,而不是所有的數(shù)據(jù)

· 

—replicate-ignore-db =db_name

意義與replicate-do-db =db_name 相反是告訴從庫數(shù)據(jù)庫sql進程忽略指定的數(shù)據(jù)庫,不進行任何復(fù)制。

 

USE prices;

UPDATE sales.january SET amount=amount+1000;

The UPDATE statement is replicated in such a case because --replicate-ignore-db applies only to the default database (determined by the USE statement). Because the sales database was specified explicitly in the statement, the statement has not been filtered. However, when using row-based replication, the UPDATEstatement's effects are not propagated to the slave, and the slave's copy of the sales.january table is unchanged; in this instance, --replicate-ignore-db=sales causes all changes made to tables in the master's copy of the sales database to be ignored by the slave.

同樣是因為“檢查默認的數(shù)據(jù)庫”導(dǎo)致被忽略的數(shù)據(jù)庫數(shù)據(jù)更新

 

· 

replicate-do-table =db_name.tbl_name

· 

告訴從庫sql進程僅復(fù)制指定的表,指定多個表多次使用這個選項。 這個選項適用于跨庫的更新和默認的數(shù)據(jù)庫更新,

· 

· 

This option affects only statements that apply to tables. It does not affect statements that apply only to other database objects, such as stored routines. To filter statements operating on stored routines, use one or more of the

· 

· 

 

· 

replicate-ignore-table =db_name.tbl_name

告訴從庫sql進程不復(fù)制指定的表,指定多個表多次使用這個選項。 這個選項適用于跨庫的更新和默認的數(shù)據(jù)庫更新,

 

· 

replicate-wild-do-table =db_name.tbl_name

· 

從庫的sql進程復(fù)制任何更新表的操作到指定的數(shù)據(jù)庫名和表名,模式可以包含‘%’和“——”通配符,like模式匹配符的操作。適用于跨庫操作

這個選項適用于表、視圖和觸發(fā)器。 它并不適用于存儲過程和函數(shù),或事件。 過濾語句后面的對象上的操作,

This option applies to tables, views, and triggers. It does not apply to stored procedures and functions, or events. To filter statements operating on the latter objects, use one or more of the

 

· 

replicate-wild-ignore-table =db_name.tbl_name

· 

從庫的sql進程不復(fù)制任何更新表的操作到指定的數(shù)據(jù)庫名和表名,模式可以包含‘%’和“——”通配符,like模式匹配符的操作。

 

參考:http://dev.mysql.com/doc/refman/5.1/en/replication-options-slave.html 

參數(shù)的使用可以參考: http://dev.mysql.com/doc/refman/5.1/en/replication-rules.html 

本文標題:MySQL主從同步部分庫跨庫問題排查分析
鏈接地址:http://www.muchs.cn/article2/gehcic.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序外貿(mào)建站、網(wǎng)站建設(shè)軟件開發(fā)、虛擬主機、全網(wǎng)營銷推廣

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名