您好,登錄后才能下訂單哦!
怎么進(jìn)行MySQL中的主主復(fù)制,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
MySQL復(fù)制技術(shù)之主主復(fù)制
1) 初始化數(shù)據(jù)庫(master1,master2)
Master1:vm1:192.168.12.181、mysqld2
Master2:vm2:192.168.12.182、mysqld2
2) 配置my.cnf
Master1:
[mysqld2]
port=3307
basedir=/usr
datadir=/data/mysql/data2
socket=/var/lib/mysql/mysql2.sock
pid-file=/var/run/mysqld/mysqld2.pid
log-error=/data/mysql/log2/mysqld2.log
user=mysql
server_id=5
log_bin=/data/mysql/log2/vm2-bin.log
relay-log=/data/mysql/log2/vm2-slave-bin.log
Master2:
[mysqld2]
port=3307
basedir=/usr
datadir=/data/mysql/data2
socket=/var/lib/mysql/mysql2.sock
pid-file=/var/run/mysqld/mysqld2.pid
log-error=/data/mysql/log2/mysqld2.log
user=mysql
server_id=6
log_bin=/data/mysql/log2/vm2-bin.log
relay-log=/data/mysql/log2/vm2-slave-bin.log
log_slave_updates=on
#slave-skip-errors=all
啟動mysql
常用參數(shù):
binlog-do-db=db_rocky #需要記錄進(jìn)制日志的數(shù)據(jù)庫.如果有多個數(shù)據(jù)庫可用逗號分隔,或者使用多個binlog-do-db選項(xiàng)
binlog-ignore-db=mysql #不需要記錄進(jìn)制日志的數(shù)據(jù)庫.如果有多個數(shù)據(jù)庫可用逗號分隔,或者使用多個binlog-do-db選項(xiàng)
replicate-do-db=db_rocky #需要進(jìn)行同步的數(shù)據(jù)庫.如果有多個數(shù)據(jù)庫可用逗號分隔,或者使用多個replicate-do-db選項(xiàng)
replicate-ignore-db=mysql,information_schema #不需要同步的數(shù)據(jù)庫.如果有多個數(shù)據(jù)庫可用逗號分隔,或者使用多個replicate-ignore-db選項(xiàng)
#同步參數(shù):
#保證slave掛在任何一臺master上都會接收到另一個master的寫入信息
log_bin=/data/mysql/log2/vm2-bin.log
relay-log=/data/mysql/log2/vm2-slave-bin.log
log_slave_updates=on
slave-skip-errors=all #過濾掉一些沒啥大問題的錯誤
3) 創(chuàng)建同步用戶
Master1:
Mysql>grant replication slave on *.* to repuser1 identified by 'aa12AA,.';
Master2:
Mysql>grant replication slave on *.* to repuser2 identified by 'aa12AA,.';
4) 連接master1與master2
master1:
mysql>change master to
master_host = '192.168.12.182',
master_port = 3307,
master_user = 'repuser2',
master_password = 'aa12AA,.';
(master_log_file ='vm2-bin.000009', master_log_pos = 1;)
Mysql>start slave;
master2:
mysql>change master to
master_host = '192.168.12.181',
master_port = 3307,
master_user = 'repuser1',
master_password = 'aa12AA,.';
(master_log_file ='vm2-bin.000009', master_log_pos = 1;)
Mysql>start slave;
看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進(jìn)一步的了解或閱讀更多相關(guān)文章,請關(guān)注億速云行業(yè)資訊頻道,感謝您對億速云的支持。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。