mysql master&slave

來源:互聯網
上載者:User

標籤:

這個東西應該有用,所以前段時間就嘗試在自己筆記本上實驗一下,結果始終沒成功。
昨天回來路上想,是該做點兒事情,遂想起了這事。

初步理解就是: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.