mysql主主同步配置

來源:互聯網
上載者:User

標籤:

mysql的主主同步實際上就是兩台伺服器之間互為主從,所以基本原理和mysql主從是一樣的,所以可以先按我的這篇部落格mysql主從同步配置 配置主從同步後, 再按以下步驟配置反向的主從同步即可,具體如下:

登入原來的從機,即Ip為192.168.0.105的伺服器

  1. 在原來的從機上本置一個用於同步的使用者,如下:

GRANT REPLICATION SLAVE ON *.* to ‘mysync‘@‘192.168.0.101‘ identified by ‘q123456‘;

2.  鎖定資料庫,如下

 

mysql> flush tables with read lock;Query OK, 0 rows affected (0.03 sec)

3. 查看主機的目前狀態(因為這時候把原來的從機當作了主機):

mysql> show master status;+------------------+----------+--------------+------------------+-------------------+| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |+------------------+----------+--------------+------------------+-------------------+| mysql-bin.000003 |      341 |              |                  |    |+------------------+----------+--------------+------------------+-------------------+1 row in set (0.00 sec)

4. 記錄下File和Position兩個欄位的值,下面配置另一台伺服器的主機時需要用到

5. 解鎖資料庫

unlock tables;Query OK, 0 rows affected (0.00 sec)


登入原來的主機,即Ip為192.168.0.105的伺服器

1. 配置對應主伺服器的資訊(這時對應的主伺服器為原來的從機即ip為192.168.0.101的伺服器)

mysql> change master to master_host=‘192.168.0.105‘,master_user=‘mysync‘,master_password=‘q123456‘, master_log_file=‘mysql-bin.000003‘,master_log_pos=341;Query OK, 0 rows affected, 2 warnings (0.91 sec)

2. 啟動從屬進程

mysql> start slave;Query OK, 0 rows affected (0.09 sec)mysql> start slave;Query OK, 0 rows affected (0.09 sec)mysql> show slave status\G*************************** 1. row ***************************               Slave_IO_State: Waiting for master to send event                  Master_Host: 192.168.0.105                  Master_User: mysync                  Master_Port: 3306                Connect_Retry: 60              Master_Log_File: mysql-bin.000003          Read_Master_Log_Pos: 341               Relay_Log_File: user-PC-relay-bin.000002                Relay_Log_Pos: 283        Relay_Master_Log_File: mysql-bin.000003             Slave_IO_Running: Yes            Slave_SQL_Running: Yes

最後使用show slave status命令查看Slave_IO_Running和Slave_SQL_RunningG兩個欄位的值都為YES即表示配置成功。


備忘:

最後貌似還要在原來的從機現在主機上再次配置對應主機的資訊才行,即重新執行以下命令

mysql> change master to master_host=‘192.168.0.101‘,master_user=‘mysync‘,master_password=‘q123456‘, master_log_file=‘mysql-bin.000001‘,master_log_pos=341;Query OK, 0 rows affected, 2 warnings (0.91 sec)

然後還需要再次重啟slave進程才行,否則在原來主機上的操作不會同步到從機上來。

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.