1、設置同步Master修改 my.cnf 文件,在
# Replication Master Server (default)
# binary logging is required for replication
添加如下內容:
log-bin=/var/log/MySQL/updatelog
server-id = 1
binlog-do-db=test
binlog-ignore-db=mysql重啟MySQL,創建一個MySQL帳號為同步專用GRANT REPLICATION SLAVE,RELOAD,SUPER, ON *.* TO
[email protected] IDENTIFIED BY 'back' ;
FLUSH PRIVILEGES ;
2、設置同步Slave修改my.cnf文件,添加
server-id = 2
master-host = 192.168.0.1
master-user = back
master-passWord = back
master-port = 3306replicate-ignore-db=MySQL
replicate-do-db=test重啟MySQL3、啟動同步在主服務器A MySQL命令符下:
show master status;
顯示(當然這個是我機器的情況,你的不可能跟我一樣哈,只是個例子):
+------------------+----------+-------------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+-------------------+------------------+
| updatelog.000028 | 313361 | test | MySQL |
+------------------+----------+-------------------+------------------+在從服務器A MySQL命令符下:
slave stop;
CHANGE MASTER TO MASTER_LOG_FILE='updatelog.000028',MASTER_LOG_POS=313361;
slave start;用show slave status\G;看一下從服務器的同步情況
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
如果都是yes,那代表已經在同步往表裡面寫點數據測試一下看是否同步成功,如果不成功,絕對不是你的RP問題,再檢查一下操作步驟!
4、設置雙向同步修改B服務器的my.cnf,添加
log-bin=/var/log/MySQL/updatelog
binlog-do-db=test
binlog-ignore-db=mysql重啟MySQL,創建一個MySQL帳號為同步專用GRANT REPLICATION SLAVE,RELOAD,SUPER, ON *.* TO
[email protected] IDENTIFIED BY 'back' ;
FLUSH PRIVILEGES ;修改A服務器的my.cnf,添加
master-host = 192.168.0.2
master-user = back
master-passWord = back
master-port = 3306replicate-ignore-db=MySQL
replicate-do-db=test重啟MySQL在主服務器B MySQL命令符下:
show master status;
+------------------+----------+-------------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+-------------------+------------------+
| updatelog.000028 | 13753 | test | MySQL |
+------------------+----------+-------------------+------------------+在服務器A MySQL命令符下:
slave stop;
CHANGE MASTER TO MASTER_LOG_FILE='updatelog.000028',MASTER_LOG_POS=13753;
slave start;其實也就是A->B單向同步的反向操作!雙向同步,就這麼簡單啦!