1. 程式人生 > >MySQL log_slave_updates 參數【轉】

MySQL log_slave_updates 參數【轉】

style fec replicat border 博客園 col date 詳細 從服務器

說明:最近部署了mysql的集群環境,詳細如下M01和M02為主主復制,M01和R01為主從復制;在測試的過程中發現了以下問題:

1、M01和M02的主主復制是沒有問題的(從M01寫入數據能同步到M02,從M02寫入數據能夠同步到M01);

2、主從同步的時候,當從M01寫入的時候,數據可以寫入到R01;

3、當從M02寫入的時候,數據就不能寫入到R01;

問題的原因:log_slave_updates參數的狀態為NO

mysql的官網說明如下:

Normally, a slave does not log to its own binary log any updates that are received from a master server. This option tells the slave to log the updates performed by its SQL thread to its own binary log. For this option to have any effect, the slave must also be started with the --log-bin option to enable binary logging. Prior to MySQL 5.5, the server would not start when using the --log-slave-updates option without also starting the server with the --log-bin option, and would fail with an error; in MySQL 5.5, only a warning is generated. (Bug #44663) --log-slave-updates is used when you want to chain replication servers. For example, you might want to set up replication servers using this arrangement:

A -> B -> C

Here, A serves as the master for the slave B, and B serves as the master for the slave C. For this to work, B must be both a master and a slave. You must start both A and B with --log-bin to enable binary logging, and B with the --log-slave-updates option so that updates received from A are logged by B to its binary log.

a) M01同步從M02同步數據過來的時候,log_slave_updates參數用來控制M01是否把所有的操作寫入到binary log,默認的情況下mysql是關閉的;

b) R01數據的更新需要通過讀取到M01的binary log才能進行更新,這個時候M01是沒有寫binary log的,所以當數據從M02寫入的時候,R01也就沒有更新了。。

問題的解決方法:

技術分享圖片

log_slave_updates:默認值為OFF;

Dynamic Variable:NO

處理方法:修改/etc/my.cnf,增加一行log_slave_updates=1,重啟數據庫後就可以了;

總結:設置完該參數後,數據庫的架構就可以設置成M01和M02為主主同步,R01通過M01進行主從同步;

應用的寫操作中M02上面進行,讀操作中R01上面進行(如果讀操作很多的話,可以在M01上面架設多臺只讀數據庫),當M02發生故障後,系統的寫操作自動遷移到M01上面。這種架構基本可以保證大部分公司的應用需求;

官網說明:

Normally, a slave does not log to its own binary log any updates that are received from a master server. This option tells the slave to log the updates performed by its SQL thread to its own binary log. For this option to have any effect, the slave must also be started with the --log-bin option to enable binary logging. Prior to MySQL 5.5, the server would not start when using the --log-slave-updates option without also starting the server with the --log-bin option, and would fail with an error; in MySQL 5.5, only a warning is generated. (Bug #44663) --log-slave-updates is used when you want to chain replication servers. For example, you might want to set up replication servers using this arrangement:

A -> B -> C


Here, A serves as the master for the slave B, and B serves as the master for the slave C. For this to work, B must be both a master and a slave. You must start both A and B with --log-bin to enable binary logging, and B with the --log-slave-updates option so that updates received from A are logged by B to its binary log.



通常情況,從服務器從主服務器接收到的更新不記入它的二進制日誌。該選項告訴從服務器將其SQL線程執行的更新記入到從服務器自己的二進制日誌。為了使該選項生效,還必須用--logs-bin選項啟動從服務器以啟用二進制日誌。如果想要應用鏈式復制服務器,應使用--logs-slave-updates。例如,可能你想要這樣設置:

A -> B -> C

也就是說,A為從服務器B的主服務器,B為從服務器C的主服務器。為了能工作,B必須既為主服務器又為從服務器。你必須用--logs-bin啟動A和B以啟用二進制日誌,並且用--logs-slave-updates選項啟動B。

轉自

主從同步設置的重要參數log_slave_updates_ITPUB博客 http://blog.itpub.net/12679300/viewspace-1319263/

Mysql log_slave_updates 參數 - 澤錦 - 博客園 https://www.cnblogs.com/zejin2008/p/4656251.html

MySQL log_slave_updates 參數【轉】