標籤:
這個東西應該有用,所以前段時間就嘗試在自己筆記本上實驗一下,結果始終沒成功。
昨天回來路上想,是該做點兒事情,遂想起了這事。
初步理解就是:master資料庫有相應的操作時,會記錄到一個binaery_log裡,然後slave去讀取這個log,然後再在自己的資料庫中進行相應的操作,從而達到同步。當然這個同步會有時間延遲。
配置:
在master和slave兩端都需要對資料庫的設定檔進行修改
master
server-id=1
auto-increment-increment=2
auto-increment-offset=1
log-bin=binary_log
binlog-do-db=同步資料庫
slave
master-host=master ip
master-user=對應在master上的使用者名稱
master-password=使用者密碼
replicate-do-db=同步資料庫
在master上建立一個slave的使用者注意這個slave使用者需要有一定的許可權
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO ’slave’@’slave ip′ IDENTIFIED BY ’slave’;
然後重啟一下master的服務(FLUSH PRIVILEGES;也可以嗎?),show master status; 記錄一下相應的log檔案和position
接著stop slave,change master to master_host=’master ip’,master_user=’master user’,master_password=’password’, master_log_file=’記錄的log檔案名稱’,master_log_pos=剛才記錄的position;
slave start.
注意:兩邊資料庫中的表結構要一致。多嘗試。
還有就是為什麼我這master上設定slave的ip是我主機ip呢。囧。
我的slave是在virtualbox中的centos
mysql master&slave