MySQL5.6 -> MySQL5.7 跨版本多源複製(Multi-Source Replication)
MySQL多源複製支援【多個低版本->MySQL 5.7】的結構
這樣就可以讓多個例項的schema匯聚在一臺例項上,而且無需升級mysql版本並避免未知風險
使用者只需要給這些例項安一個MySQL 5.7作為slave就可以了
當然Slave必須為MySQL 5.7
本次實驗將使用MySQL 5.6.x作為多“主”。
〇 測試環境:
OS:CentOS 6.5
master_1: 192.168.1.185(MySQL 5.6.30)
master_2: 192.168.1.186(MySQL 5.6.30)
slave: 192.168.1.1.187(MySQL 5.7.15)
〇 配置:
master_1相關配置:
master_2相關配置:
slave相關配置:
〇 為master_1 & master_2上建立複製使用者:
〇 測試資料準備:
master_1測試資料:
master_2測試資料:
〇 在slave上執行:
最後通過start slave status即可查到複製狀態
〇 測試:
master_1上操作:
master_2上操作:
slave上操作:
〇 其他相關語法:
ps.
與上述傳統position方式類似,GTID方式配置起來也類似,開啟GTID後,需要注意使用FOR CHANNEL 'xxx'關鍵字即可,比如:
多臺主機的schema名字不可以一樣,(比如master_1為db_00 ... db_09共10庫,master_2為db_10 ... db_19,master_3為db_20 ... db_29 ……)
參考文件:
MySQL 5.7 Reference Manual 14 SQL Statement Syntax - 14.4.2.1 CHANGE MASTER TO Syntax
MySQL 5.7 Reference Manual 18 Replication - 18.1.4 MySQL Multi-Source Replication
作者微信公眾號(持續更新)
這樣就可以讓多個例項的schema匯聚在一臺例項上,而且無需升級mysql版本並避免未知風險
使用者只需要給這些例項安一個MySQL 5.7作為slave就可以了
當然Slave必須為MySQL 5.7
本次實驗將使用MySQL 5.6.x作為多“主”。
〇 測試環境:
OS:CentOS 6.5
master_1: 192.168.1.185(MySQL 5.6.30)
master_2: 192.168.1.186(MySQL 5.6.30)
slave: 192.168.1.1.187(MySQL 5.7.15)
〇 配置:
master_1相關配置:
-
[mysqld]
-
server_id = 185
-
log-bin = master_1
- log-bin-index = master_1.index
master_2相關配置:
-
[mysqld]
-
server_id = 186
-
log-bin = master_2
- log-bin-index = master_2.index
slave相關配置:
-
[mysqld]
-
server_id = 187
-
relay-log = slave
-
relay-log-index = slave.index
-
-
# 多源複製結構中的slave,官方要求master-info和relay-log-info存放處必須為TABLE.
-
# 如果為FILE,則在新增多個master時,會失敗:ER_SLAVE_NEW_CHANNEL_WRONG_REPOSITORY.
-
master-info-repository = TABLE
- relay-log-info-repository = TABLE
〇 為master_1 & master_2上建立複製使用者:
-
GRANT REPLICATION SLAVE ON *.* to repl@'192.168.1.187' IDENTIFIED BY 'repl';
- FLUSH PRIVILEGES;
〇 測試資料準備:
master_1測試資料:
-
master_1> FLUSH LOGS;
-
Query OK, 0 rows affected (0.00 sec)
-
-
master_1> SHOW BINARY LOGS; -- 記住當前binlog的name和position
-
+-----------------+-----------+
-
| Log_name | File_size |
-
+-----------------+-----------+
-
| master_1.000001 | 166 |
-
| master_1.000002 | 455 |
-
| master_1.000003 | 120 |
-
+-----------------+-----------+
- 3 rows in set (0.00 sec)
-
-
master_1> CREATE DATABASE master_1;
- Query OK, 1 row affected (0.03 sec)
master_2測試資料:
-
master_2> FLUSH LOGS;
-
Query OK, 0 rows affected (0.00 sec)
-
-
master_2> SHOW BINARY LOGS; -- 記住當前binlog的name和position
-
+-----------------+-----------+
-
| Log_name | File_size |
-
+-----------------+-----------+
-
| master_2.000001 | 166 |
-
| master_2.000002 | 455 |
-
| master_2.000003 | 120 |
-
+-----------------+-----------+
-
3 rows in set (0.00 sec)
-
-
master_2> CREATE DATABASE master_2;
- Query OK, 1 row affected (0.02 sec)
〇 在slave上執行:
-
salve> CHANGE MASTER TO
-
-> MASTER_HOST='192.168.1.185',
-
-> MASTER_USER='repl',
-
-> MASTER_PORT=3306,
-
-> MASTER_PASSWORD='repl',
-
-> MASTER_LOG_FILE='master_1.000003',
-
-> MASTER_LOG_POS=120
-
-> FOR CHANNEL 'master_1';
-
Query OK, 0 rows affected, 2 warnings (0.02 sec) -- 此處產生的warnings是一些安全建議和警告,本實驗無視。
-
-
salve> CHANGE MASTER TO
-
-> MASTER_HOST='192.168.1.186',
-
-> MASTER_USER='repl',
-
-> MASTER_PORT=3306,
-
-> MASTER_PASSWORD='repl',
-
-> MASTER_LOG_FILE='master_2.000003',
-
-> MASTER_LOG_POS=120
-
-> FOR CHANNEL 'master_2';
-
Query OK, 0 rows affected, 2 warnings (0.02 sec)
-
-
slave> START SLAVE;
-
Query OK, 0 rows affected (0.01 sec)
-
-
salve> SHOW DATABASES; -- 此時在master_1和master_2上的binlog events已經被正常的apply了
-
+--------------------+
-
| Database |
-
+--------------------+
-
| information_schema |
-
| master_1 |
-
| master_2 |
-
| mysql |
-
| performance_schema |
-
| sys |
-
+--------------------+
- 6 rows in set (0.00 sec)
最後通過start slave status即可查到複製狀態
-
slave> SHOW SLAVE STATUS\G
-
*************************** 1. row ***************************
-
Slave_IO_State: Waiting for master to send event
-
Master_Host: 192.168.1.185
-
Master_User: repl
-
Master_Port: 3306
-
……………………………………………………
-
Slave_IO_Running: Yes
-
Slave_SQL_Running: Yes
-
……………………………………………………
-
Master_Server_Id: 185
-
Master_UUID: ee1f8704-58c4-11e6-95b5-000c297f23b7
-
Master_Info_File: mysql.slave_master_info
-
SQL_Delay: 0
-
SQL_Remaining_Delay: NULL
-
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
-
……………………………………………………
-
Channel_Name: master_1
-
Master_TLS_Version:
-
*************************** 2. row ***************************
-
Slave_IO_State: Waiting for master to send event
-
Master_Host: 192.168.1.186
-
Master_User: repl
-
Master_Port: 3306
-
Connect_Retry: 60
-
……………………………………………………
-
Slave_IO_Running: Yes
-
Slave_SQL_Running: Yes
-
……………………………………………………
-
Master_Server_Id: 186
-
Master_UUID: 53774f2d-7e14-11e6-8900-000c298e914c
-
Master_Info_File: mysql.slave_master_info
-
SQL_Delay: 0
-
SQL_Remaining_Delay: NULL
-
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
-
……………………………………………………
-
Channel_Name: master_2
-
Master_TLS_Version:
- 2 rows in set (0.00 sec)
〇 測試:
master_1上操作:
-
master_1> CREATE TABLE master_1.test_table(id int);
- Query OK, 0 rows affected (0.05 sec)
-
-
master_1> INSERT INTO master_1.test_table SELECT 666666;
-
Query OK, 1 row affected (0.01 sec)
- Records: 1 Duplicates: 0 Warnings: 0
master_2上操作:
-
master_2> CREATE TABLE master_2.test_table(massage varchar(16));
-
Query OK, 0 rows affected (0.02 sec)
-
-
master_2> INSERT INTO master_2.test_table SELECT '嘿嘿嘿';
-
Query OK, 1 row affected (0.00 sec)
-
Records: 1 Duplicates: 0 Warnings: 0
-
-
master_2> INSERT INTO master_2.test_table SELECT '三陽之炎';
-
Query OK, 1 row affected (0.00 sec)
- Records: 1 Duplicates: 0 Warnings: 0
slave上操作:
-
salve> SELECT id FROM master_1.test_table;
-
+--------+
-
| id |
-
+--------+
-
| 666666 |
-
+--------+
-
1 row in set (0.00 sec)
-
-
-
salve> SELECT massage FROM master_2.test_table;
-
+--------------+
-
| massage |
-
+--------------+
-
| 嘿嘿嘿 |
-
| 三陽之炎 |
-
+--------------+
- 2 rows in set (0.00 sec)
〇 其他相關語法:
-
START/STOP/RESET ALL/RESET SLAVE FOR CHANNEL 'XXX';
-
- SHOW SLAVE STATUS FOR CHANNEL 'XXX';
ps.
與上述傳統position方式類似,GTID方式配置起來也類似,開啟GTID後,需要注意使用FOR CHANNEL 'xxx'關鍵字即可,比如:
-
CHANGE MASTER TO
-
MASTER_HOST='',
-
MASTER_USER='repl',
-
MASTER_PORT=3306,
-
MASTER_PASSWORD='repl',
-
MASTER_AUTO_POSITION = 1
- FOR CHANNEL 'master_1';
多臺主機的schema名字不可以一樣,(比如master_1為db_00 ... db_09共10庫,master_2為db_10 ... db_19,master_3為db_20 ... db_29 ……)
參考文件:
MySQL 5.7 Reference Manual 14 SQL Statement Syntax - 14.4.2.1 CHANGE MASTER TO Syntax
MySQL 5.7 Reference Manual 18 Replication - 18.1.4 MySQL Multi-Source Replication
作者微信公眾號(持續更新)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29773961/viewspace-2125164/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Redis 主從複製(Replication)Redis
- mysql5.7主從複製,主主複製MySql
- MySQL5.7主從複製-半同步複製搭建MySql
- Mysql5.7半同步複製MySql
- Redis replication主從複製原理及配置Redis
- [Mysql]Mysql5.7並行複製MySql並行
- MySQL5.7主從複製教程MySql
- mysql5.6主主複製及keepalived 高可用MySql
- MySQL5.7半同步複製報錯案例分析MySql
- #MySQL# mysql5.7新特性之半同步複製MySql
- Mysql 5.7 基於組複製(MySQL Group Replication) - 運維小結MySql運維
- MySQL 多源複製MySql
- MySQL案例07:MySQL5.7併發複製隱式bugMySql
- VMware vSphere Replication 9.0 - 虛擬機器複製和資料保護虛擬機
- MySQL5.7在滴滴雲主機上的主從複製MySql
- Raft演算法系列教程2:狀態機複製 (State Machine Replication)Raft演算法Mac
- maven 打包不複製資源Maven
- 淺複製和深複製的概念與值複製和指標複製(引用複製)有關 淺複製 “指標複製 深複製 值複製指標
- Sql Server實時監控釋出訂閱複製Replication、subscription有多少延遲的方法SQLServer
- mysql5.7 GTID 主從複製模式-增加新的slave1(好文章!!)MySql模式
- Java引用複製、淺複製、深複製Java
- JS物件複製:深複製和淺複製JS物件
- 複製和引用複製
- poi操作excel,複製sheet,複製行,複製單元格,複製styleExcel
- Oracle跨主機複製資料庫背後的意義Oracle資料庫
- SovitJs新增跨場景複製元件、新增地面背景等功能JS元件
- 淺複製與深複製
- MySQL 8 複製(三)——延遲複製與部分複製MySql
- MySQL5.7綠色版安裝MySql
- MySQL5.7高可用版釋出MySql
- mysql複製--主從複製配置MySql
- python 淺複製、深複製坑Python
- python 深複製和淺複製Python
- JavaScript 淺複製和深複製JavaScript
- 系統變數group_replication_group_seeds為空導致MySQL節點無法啟動組複製變數MySql
- Geo-replication: 從 Copysets 到 Tiered Replication
- 複製
- MySQL 5.7 多主一從(多源複製)同步配置MySql
- mysql多源複製跳過錯誤處理方法MySql