《MYSQL數(shù)據(jù)庫MySQL 數(shù)據(jù)庫雙向鏡像、循環(huán)鏡像(復制)》要點:
本文介紹了MYSQL數(shù)據(jù)庫MySQL 數(shù)據(jù)庫雙向鏡像、循環(huán)鏡像(復制),希望對您有用。如果有疑問,可以聯(lián)系我們。
對于雙向數(shù)據(jù)庫鏡像,就是數(shù)據(jù)庫A的數(shù)據(jù)變化要鏡像到數(shù)據(jù)庫B中,同時數(shù)據(jù)庫B里的修改也要同時復制到數(shù)據(jù)庫A里.
對于循環(huán)數(shù)據(jù)庫鏡像,就是多個數(shù)據(jù)庫A、B、C、D等,對其中任一個數(shù)據(jù)庫的修改,都要同時鏡像到其它的數(shù)據(jù)庫里.
應用:同一個Zen Cart網(wǎng)店的數(shù)據(jù)庫和程序,可以放置在不同的主機上,在任一臺主機上新增的訂單、客戶資料,都會同時加入其它的主機數(shù)據(jù)庫里.
要實現(xiàn)雙向或循環(huán)數(shù)據(jù)庫鏡像,首先要解決的就是防止數(shù)據(jù)庫中自動遞增(AUTO_INCREMENT)字段的沖突,以免多數(shù)據(jù)庫各自生成一樣的增量值.
下面以三臺主機循環(huán)鏡像為例,A是B的主鏡像,B是C的主鏡像,C是A的主鏡像.三臺主機上MySQL設置文件 /etc /my.cnf 中分別加入下面的參數(shù):
# 主機一:美國主機 A, IP: 100.101.102.201
[mysqld]
server-id = 10
log-bin = mysql-bin
log-slave-updates
replicate-same-server-id = 0
auto_increment_increment = 10
auto_increment_offset = 1
master-host = 100.101.102.203
master-user = repl_user
master-password = repl_password
report-host = 100.101.102.201
# 主機二:中國主機 B, IP: 100.101.102.202
[mysqld]
server-id = 20
log-bin = mysql-bin
log-slave-updates
replicate-same-server-id = 0
auto_increment_increment = 10
auto_increment_offset = 2
master-host = 100.101.102.201
master-user = repl_user
master-password = repl_password
report-host = 100.101.102.202
# 主機三:本地主機 C, IP: 100.101.102.203
[mysqld]
server-id = 30
log-bin = mysql-bin
log-slave-updates
replicate-same-server-id = 0
auto_increment_increment = 10
auto_increment_offset = 3
master-host = 100.101.102.202
master-user = repl_user
master-password = repl_password
report-host = 100.101.102.203
簡單說明:
server-id:數(shù)據(jù)庫標識,每個數(shù)據(jù)庫標識必須唯一;
replicate-same-server-id:設置為0,防止數(shù)據(jù)循環(huán)更新;
auto_increment_increment:這是循環(huán)鏡像里最重要的參數(shù)之一,表示自動增量為10,這將允許最多10臺數(shù)據(jù)庫加入這個循環(huán)鏡像的陣列,而自動遞增字段不會重復.
auto_increment_offset:這是循環(huán)鏡像里最重要的參數(shù)之一,表示偏移值,每個數(shù)據(jù)庫的偏移值必須唯一,且在1和auto_increment_increment之間.
master-host:主數(shù)據(jù)庫服務器的IP;
master-user:用于連接主數(shù)據(jù)庫的鏡像用戶名;
master-password:用于連接主數(shù)據(jù)庫的鏡像密碼;
report-host:提供給主數(shù)據(jù)庫用于反向連接的IP,因為主數(shù)據(jù)庫有時無法正確判斷從服務器的IP,所以這里最好填上從服務器自己的IP地址.
另外,有時只需要鏡像某些數(shù)據(jù)庫,可以在 my.cnf 中加入:
replicate-do-db = db_name1
replicate-do-db = db_name2
replicate-do-db = db_name3
這樣就僅僅鏡像db_name1/db_name2/db_name3
如果只是某些數(shù)據(jù)庫不要鏡像,可以在 my.cnf 中加入:
replicate-ignore-db=db_name1
replicate-ignore-db=db_name2
replicate-ignore-db=db_name3
這樣鏡像時就忽略 db_name1/db_name2/db_name3 這三個數(shù)據(jù)庫.
維易PHP培訓學院每天發(fā)布《MYSQL數(shù)據(jù)庫MySQL 數(shù)據(jù)庫雙向鏡像、循環(huán)鏡像(復制)》等實戰(zhàn)技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養(yǎng)人才。
轉載請注明本頁網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/11960.html