《Mycat學習筆記》 第三篇. MySql 主從同步異常後,主從切換

來源:互聯網
上載者:User

標籤:

1)系統內容說明

MySql 5.5 主從節點

127.0.0.1:3306   主結點,為驗證主從轉場效果,手動停止服務

127.0.0.1: 3307    從結點 1 

127.0.0.1:338     從結點 2 ,為驗證主從轉場效果,在主結點停止後,新增兩個記錄。

 

MyCat 1.5 schema.xml 配置

具體配置說明,參考上篇: 《Mycat學習筆記》 第二篇. MySql 讀寫分離與日誌分析——主從多結點 

<dataHost name="localhost1" maxCon="1000" minCon="10" balance="1"
  writeType="0" dbType="mysql" dbDriver="native" switchType="2" slaveThreshold="100">
  <heartbeat>show slave status</heartbeat>
  <!-- can have multi write hosts -->
  <writeHost host="hostM1" url="localhost:3306" user="root" password="root123">
    <!-- can have multi read hosts -->
    <readHost host="hostS1" url="localhost:3307" user="root" password="root123" />
  </writeHost>

  <writeHost host="hostM2" url="localhost:3308" user="root" password="root123"></writeHost>

</dataHost>

 

2)整體切換流程

  • 原主機(3306)停止服務
  • MyCat 自動檢測進行主從切換(hostM1轉為hostM2)
  • 通過mycat insert data,資料只在 3308 的資料庫中體現
  • 啟動原主機mysql 3306 服務
  • 手動同步資料 mysql workbench (暫時不知道別的方法,)
  • 調整mysql master 和 slave的關係 ,將3308設為主機,3306設為從機,3307配置不動
  • 通過mycat 驗證新的主從配置
  • mycat 不用重啟,服務會自動切換

 

3)具體操作步驟

3.1)停止3308 環境 slave模式 並 開啟 master 

停止slave 

mysql> stop slave;

 

配置3308為主機模式

mysql> GRANT REPLICATION SLAVE ON *.* to ‘mycat_sync_3308‘@‘%‘ identified by ‘mycat_sync_3308‘;
Query OK, 0 rows affected (0.00 sec)

 

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

 

3.2)3306 環境開啟slave 

 

 

3.3)原master機切換為slave模式

 

3.4)資料驗證

 

3.5)mycat 驗證

 

《Mycat學習筆記》 第三篇. 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.