Mysql主主複製

來源:互聯網
上載者:User

標籤:mysql 主主複製

Mysql主主複製

    背景:

    將學習到的Mysql主主複製方式做個記錄。

    介紹:

    所謂的主主複製也就是兩台Mysql伺服器都可以對外提供讀寫服務,並且是同時服務。

    實現:

    步驟1、在兩台伺服器上都安裝Mysql服務和客服端工具

        yum install mysql-server mysql

    步驟2、編輯設定檔

        1)互為主從:兩個節點各自都要開啟binlog和relay log;
        2)server_id必須要使用不同值;
        3)均啟用binlog和relay log;
        4)存在自動成長id的表,為了使得id不相衝突,需要定義其自動成長方式;

            自動成長id;
                定義一個節點使用奇數id
                    auto_increment_offset=1
                    auto_increment_increment=2
                另一個節點使用偶數id
                    auto_increment_offset=2
                    auto_increment_increment=2
           

        

650) this.width=650;" src="https://s5.51cto.com/oss/201711/14/2568b5c5f15c7205d869199c68911de1.png" title="1.png" alt="2568b5c5f15c7205d869199c68911de1.png" />

    步驟3、開啟Mysql服務,添加雙方同步帳號

         命令:GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO ‘test‘@‘172.18.76.%‘ IDENTIFIED BY ‘123456‘;

650) this.width=650;" src="https://s4.51cto.com/oss/201711/14/746877adbb4dba408167c0ab1c672081.png" title="2.png" alt="746877adbb4dba408167c0ab1c672081.png" />

    步驟4、啟動服務並查看雙方記錄檔及位移量

        service mysqld start

        第一台主機:

        650) this.width=650;" src="https://s4.51cto.com/oss/201711/14/e3b2e691543c8c8e833f537963b195c3.png" title="3.png" alt="e3b2e691543c8c8e833f537963b195c3.png" />

        第二台主機:

        650) this.width=650;" src="https://s3.51cto.com/oss/201711/14/cb48c14d27883a5ee41ca246feb8e550.png" title="4.png" alt="cb48c14d27883a5ee41ca246feb8e550.png" />

    步驟5、添加對方為自己的主節點伺服器,開啟從節點

        650) this.width=650;" src="https://s4.51cto.com/oss/201711/14/b1477e29f8c7c9374ec957afb1c67764.png" title="5.png" alt="b1477e29f8c7c9374ec957afb1c67764.png" />

650) this.width=650;" src="https://s2.51cto.com/oss/201711/14/a48737d92b14877d61787ec6a84c19b4.png" title="6.png" alt="a48737d92b14877d61787ec6a84c19b4.png" />

    步驟6、測試

        在兩台主機上各建一個資料庫,看對方是否成功同步;

        650) this.width=650;" src="https://s3.51cto.com/oss/201711/14/930e649c221d117cd5247957ff5a9f07.png" title="7.png" alt="930e649c221d117cd5247957ff5a9f07.png" />

        同時在第二台資料庫查看是否同步了資料庫

        650) this.width=650;" src="https://s2.51cto.com/oss/201711/14/ee728fdaf3f52d6865bdea42264cdc0f.png" title="8.png" alt="ee728fdaf3f52d6865bdea42264cdc0f.png" />

        到此Mysql資料庫的主主複製完成


        

Mysql主主複製

聯繫我們

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