MySQL雙向複製(主主模式)

來源:互聯網
上載者:User

MySQL雙向複製(主主模式)

環境:

A: 192.168.1.1    沒有資料

B: 192.168.1.2    沒有資料

在A的[mysqld]欄位下增加:

auto-increment-increment = 2 (增長值) A上就會 1,3,5,7這樣增長

auto-increment-offset = 1    (初始值)

在B的[mysqld]欄位下增加:

auto-increment-increment = 2  (增長值) B上就會2,4,6,8這樣增長

auto-increment-offset = 2      (初始值)

因為是雙向備份,可能產生主鍵重複等問題,添加這兩個參數防止主鍵重複

注意:server-id = 1 改成 server-id = 2

重啟資料庫

在A上

mysql> grant replication slave on *.* to 'beifen'@'192.168.1.2' identified by '123'; 建立 beifen使用者,密碼設定為123  並授權給192.168.1.2使用。

在B上

mysql> grant replication slave on *.* to 'beifen'@'192.168.1.1' identified by '123'; 建立 beifen使用者,密碼設定為123  並授權給192.168.1.1使用。

在A上:

查詢主要資料庫的狀態,並記下File和Position的值,

在B上

在A上:

mysql>change master to master_host=’192.168.1.2’,master_user=’beifen’,master_password=’123’,master_log_file=’mysql-bin.000016’ ,master_log_pos=106;

在B上:

mysql>change master to master_host=’192.168.1.1’,master_user=’beifen’,master_password=’123’,master_log_file=’mysql-bin.000010’ ,master_log_pos=257;

在A .、B上分別執行

啟動slave同步

mysql > start slave;

在A、B上分別檢查主從同步,如果您看到Slave_IO_Running和Slave_SQL_Running均為Yes,則主從複製串連正常。

mysql > show slave status\G

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.