標籤:style blog color io os ar for strong 資料
外網資料庫為主,內網資料庫為從。首先確保主要資料庫所在的伺服器防火牆開啟。
如果資料庫在做主從的時候已經有資料了, 則需要進行鎖表操作.
mysql> flush tables with read lock;
記住資料導完後要解鎖:
mysql> unloclk tables;
一.配置主要資料庫master
1.配置master主要資料庫
[mysqld]server-id = 1 //分配server-idlog-bin = master-bin //預設mysql-bin,可以不修改
2.在master建立同步帳號:
grant replication client,replication slave on *.* to [email protected]‘218.108.90.94‘ identified by ‘repl‘ ;
3.查看binlog日誌:
show master status;
查看A的狀態,記錄下file的位置和postion的參數
二 .配置slave從資料庫
1.配置從資料庫
server-id=208log-bin=mysql-bin //建議log-bin功能也開啟binlog-format=mixedrelay-log=mysql-relay
2. 指向主要資料庫
先關閉slave stop slave;
CHANGE MASTER TO MASTER_HOST=‘server A ip‘,MASTER_PORT=3306,MASTER_USER=‘user‘,MASTER_PASSWORD=‘password‘,MASTER_LOG_FILE=‘mysql-bin.000001‘,MASTER_LOG_POS=0;
開啟slave :start slave;
查看slave狀態:show slave status;
ps: 如果要刪除slave資訊可以
change master to master_host = ‘‘;然後 reset slave;
mysql主從複製