其實這步驟跟一般的雙master設定差不多,只是在有個小地方要注意,就是放拷貝檔案的主機,必須要先將檔案搬好後再去查master的log位置,

之後再到a台去設定可以連到b台


在A台已經裝有MYSQL,且已經有資料,現在要讓B台與A台做出MASTER-MASTER架構

1.先在A台裝MYSQL 且新增了Database  aaa  也新增table Custmer

2.B台也開始裝myslq並且設定使用mysql帳密

3.到A的my.cnf打上

server-id=1  log-bin=mysql-bin  

重開mysql , 登入後打 show master status 查詢 Log file & log position

4.到B的my.cnf打上

server-id=2  log-bin=mysql-bin  

重開mysql , **登入後打 show master status 先不要查詢 Log file & log position,因

為等等把a台的資料備份到此,log位置會跑掉,所以等備份好後再查詢**


5.先到DB2執行

#grant replication slave on *.* to 'replication'@’對方localhost’  identified by

 'password';

#flush privileges; (建立一個帳號讓對方可以連到自己主機)

#change master to master_host='對方localhost', master_port=3307, master_user='replication', master_password='password';

mysqldump -u root -p --master-data --all-databases > all_mysql_db.sql

6.到DB1把所有資料庫做備份

#mysqldump -u root -p --master-data --all-databases > all_mysql_db.sql

7.將all_mysql_db.sql拷貝到B台/OPT/下

#SCP all_mysql_db.sql root@slave1:/opt/

8.到b台將資料放到mysql

# mysql -u root -p --default-character-set=utf8 < all_mysql_db.sql

9.到DB2查詢MASTER位置

# show master status;

10. DB1執行

#grant replication slave on *.* to 'replication'@’對方localhost’  identified by 'password';

#flush privileges; (建立一個帳號讓對方可以連到自己主機)

#change master to master_host='對方localhost', master_port=3307, master_user='replication', master_password='password';

11. DB1DB2重新啟動 

service mysql restart

12. DB1執行,並檢查狀態是否成功

start slave;   show slave status;

13. DB2執行,並檢查狀態是否成功

start slave;   show slave status;

14. 分別在DB1DB2新增/修改/刪除資料,驗證是否成功



arrow
arrow
    全站熱搜
    創作者介紹
    創作者 beyound2 的頭像
    beyound2

    beyound2的部落格

    beyound2 發表在 痞客邦 留言(0) 人氣()