標籤:
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 主從同步異常後,主從切換