MySQL入門--MySQL複製技術之主主複製

panpong發表於2017-01-27

MySQL複製技術之主主複製

1) 初始化資料庫(master1master2

Master1:vm1:192.168.12.181mysqld2

Master2:vm2:192.168.12.182mysqld2

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

 

常用引數:

binlog-do-db=db_rocky #需要記錄進位制日誌的資料庫.如果有多個資料庫可用逗號分隔,或者使用多個binlog-do-db選項

binlog-ignore-db=mysql #不需要記錄進位制日誌的資料庫.如果有多個資料庫可用逗號分隔,或者使用多個binlog-do-db選項

replicate-do-db=db_rocky #需要進行同步的資料庫.如果有多個資料庫可用逗號分隔,或者使用多個replicate-do-db選項

replicate-ignore-db=mysql,information_schema #不需要同步的資料庫.如果有多個資料庫可用逗號分隔,或者使用多個replicate-ignore-db選項

#同步引數:

#保證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) 建立同步使用者

Master1:

Mysql>grant replication slave on *.* to repuser1 identified by 'aa12AA,.';

Master2:

Mysql>grant replication slave on *.* to repuser2 identified by 'aa12AA,.';

 

4) 連線master1master2

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;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/16976507/viewspace-2132953/,如需轉載,請註明出處,否則將追究法律責任。

相關文章