MySQL 5.7搭建多源複製
MySQL 5.7版本支援多源複製,MySQL 5.5和5.6不支援。
多源複製可以讓多個主節點同時並行進行復制到一個從節點上。一個slave為每個master建立一個複製通道。
至少需要兩臺主庫和一臺從庫。
多源複製中的主庫,可以配置成基於全域性事務標準(GTID)的複製,或者基於二進位制日誌的複製。
IP規劃
主庫01 192.168.174.201
主庫02 192.168.174.202
從庫 192.168.174.203
1. 在多源複製的從庫中,需要基於表的repositories,和基於檔案的repositories不相容。
在從庫上面操作
可以將下面引數新增到引數檔案中
master-info-repository=TABLE
relay-log-info-repository=TABLE
master_info_repository
決定包含master狀態和連線資訊的slave日誌,是以檔案格式(master.info),還是以表格式(mysql.slave_master_info)存在。
當沒有複製執行緒執行的時候,可以改變這個引數的值。
這個引數還會對sync_master_info系統引數有直接的影響。
relay_log_info_repository
這個引數決定寫到檔案(relay-log.info)或表(mysql.slave_relay_log_info)中的中繼日誌slave節點的位置。只有當沒有複製執行緒執行時,才可修改這個引數的值。
這個引數用於存放中繼日誌的資訊。預設是檔案格式,檔案的預設名是relay-log.info。
如果是TABLE格式,日誌資訊會寫到mysql.slave_relay_log_info。
動態修改,使用下面命令
STOP SLAVE;
SET GLOBAL master_info_repository = 'TABLE';
STOP SLAVE;
SET GLOBAL relay_log_info_repository = 'TABLE';
mysql> show global variables like '%repositor%';
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| master_info_repository | FILE |
| relay_log_info_repository | FILE |
+---------------------------+-------+
2 rows in set (0.03 sec)
mysql> SET GLOBAL master_info_repository = 'TABLE';
Query OK, 0 rows affected (0.00 sec)
mysql> SET GLOBAL relay_log_info_repository = 'TABLE';
ERROR 1766 (HY000): Unknown error 1766
mysql> stop slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show global variables like '%repositor%';
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| master_info_repository | TABLE |
| relay_log_info_repository | TABLE |
+---------------------------+-------+
2 rows in set (0.01 sec)
編輯從庫的其他配置檔案
[root@localhost 5505]# vim /mysql_data/cnf/my.cnf
# Log
server-id = 300
log-bin = /mysql_log/binlog/mysql-bin
relay-log = /mysql_log/binlog/product-relay-bin
relay-log-index = /mysql_log/binlog/product-relay-index
之後重啟資料庫,使得引數生效
2. 修改主庫1和主庫2引數檔案,建立複製使用者,建立測試資料
編輯主庫的配置檔案,注意,每個庫的server-id不能相同
[root@localhost install]# vim /etc/my.cnf
# Log
server-id = 100
log-bin = /log/binlog/mysql-bin
之後重啟資料庫,使得引數生效
建立複製使用者
mysql> grant replication slave on *.* to 'repl'@'192.168.174.%' identified by 'repl';
Query OK, 0 rows affected, 1 warning (0.06 sec)
mysql> select version();
+---------------+
| version() |
+---------------+
| 5.7.17-11-log |
+---------------+
1 row in set (0.00 sec)
建立測試資料
主庫1
mysql> create database sale;
Query OK, 1 row affected (0.06 sec)
mysql> use sale;
Database changed
mysql> create table sale_record(id int);
Query OK, 0 rows affected (0.16 sec)
mysql> insert into sale_record values(10),(20);
Query OK, 2 rows affected (0.95 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.01 sec)
主庫2
mysql> use market;
Database changed
mysql> create table market_record(id int)
-> ;
Query OK, 0 rows affected (0.04 sec)
mysql> insert into market_record values (100),(200);
Query OK, 2 rows affected (0.25 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.01 sec)
3. 備份主庫1和主庫2
主庫1
[root@MySQL01 mysql_software_57]# bin/mysqldump -uroot -p'root' -h 127.0.0.1 -q --single-transaction --master-data=2 -B sale > /tmp/20171211_sale.sql
主庫2
[root@localhost mysql_software_57]# bin/mysqldump -uroot -p'root' -S /mysql_data_57/mysql.sock -q --single-transaction --master-data=2 -B market > /tmp/20171211_market.sql
將主庫1和主庫2上面的備份檔案複製到從庫上面,進行恢復
在從庫上面操作
[root@MySQL03 mysql_software_57]# bin/mysql -uroot -p'root' -h 127.0.0.1 < /tmp/20171211_sale.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@MySQL03 mysql_software_57]# bin/mysql -uroot -p'root' -h 127.0.0.1 < /tmp/20171211_market.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
4. 搭建多源複製
搭建到主庫1的複製,將通道起名為master-1
mysql> change master to
-> master_host='192.168.174.201',
-> master_port=3306,
-> master_user='repl',
-> master_password='repl',
-> master_log_file='mysql-bin.000017',
-> master_log_pos=1209
-> FOR CHANNEL 'master-1';
Query OK, 0 rows affected, 1 warning (0.04 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.174.201
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000017
Read_Master_Log_Pos: 1209
Relay_Log_File: mysqld-relay-bin-master@002d1.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin.000017
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1209
Relay_Log_Space: 154
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
Master_UUID:
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name: master-1
Master_TLS_Version:
1 row in set (0.00 sec)
啟動通道master-1的IO和SQL執行緒
mysql> START SLAVE IO_THREAD FOR CHANNEL 'master-1';
Query OK, 0 rows affected (0.00 sec)
mysql> START SLAVE SQL_THREAD FOR CHANNEL 'master-1';
Query OK, 0 rows affected (0.01 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.174.201
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000017
Read_Master_Log_Pos: 1209
Relay_Log_File: mysqld-relay-bin-master@002d1.000002
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000017
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1209
Relay_Log_Space: 541
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 203fe772-177e-11e7-b15c-000c296b3b20
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
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name: master-1
Master_TLS_Version:
1 row in set (0.00 sec)
啟動通道master-2的IO執行緒和SQL執行緒
mysql> change master to
-> master_host='192.168.174.202',
-> master_port=3306,
-> master_user='repl',
-> master_password='repl',
-> master_log_file='mysql-bin.000014',
-> master_log_pos=1239
-> FOR CHANNEL 'master-2';
Query OK, 0 rows affected, 1 warning (0.02 sec)
mysql> START SLAVE IO_THREAD FOR CHANNEL 'master-2';
Query OK, 0 rows affected (0.00 sec)
mysql> START SLAVE SQL_THREAD FOR CHANNEL 'master-2';
Query OK, 0 rows affected (0.01 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.174.201
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000017
Read_Master_Log_Pos: 1481
Relay_Log_File: mysqld-relay-bin-master@002d1.000002
Relay_Log_Pos: 592
Relay_Master_Log_File: mysql-bin.000017
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1481
Relay_Log_Space: 813
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 203fe772-177e-11e7-b15c-000c296b3b20
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
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name: master-1
Master_TLS_Version:
*************************** 2. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.174.202
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000014
Read_Master_Log_Pos: 1239
Relay_Log_File: mysqld-relay-bin-master@002d2.000002
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000014
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1239
Relay_Log_Space: 541
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 2
Master_UUID: 2efd664c-177f-11e7-8323-000c29fcf2cd
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
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name: master-2
Master_TLS_Version:
2 rows in set (0.01 sec)
進行測試
在主庫1上面插入資料
mysql> insert into sale_record values(30),(40),(50);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.01 sec)
在主庫2上面插入資料
mysql> insert into market_record values(300),(400),(500);
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.01 sec)
在從庫上面進行查詢
mysql> select * from sale.sale_record;
+------+
| id |
+------+
| 10 |
| 20 |
| 30 |
| 40 |
| 50 |
+------+
5 rows in set (0.00 sec)
mysql> select * from market.market_record;
+------+
| id |
+------+
| 100 |
| 200 |
| 300 |
| 400 |
| 500 |
+------+
5 rows in set (0.00 sec)
常用命令
啟動多源複製
啟動所有配置的複製通道的IO執行緒
mysql> start slave io_thread;
Query OK, 0 rows affected (0.01 sec)
啟動所有配置的複製通道的SQL執行緒
mysql> start slave sql_thread;
Query OK, 0 rows affected (0.01 sec)
啟動指定的複製通道
mysql> start slave io_thread for channel 'master-1';
Query OK, 0 rows affected (0.00 sec)
停止多源複製
停止所有配置的複製通道的IO執行緒
mysql> stop slave io_thread;
Query OK, 0 rows affected (0.01 sec)
停止所有配置的複製通道的SQL執行緒
mysql> stop slave sql_thread;
Query OK, 0 rows affected (0.00 sec)
停止指定的複製通道
mysql> stop slave sql_thread for channel 'master-1';
Query OK, 0 rows affected, 1 warning (0.00 sec)
重置多源複製的從庫
重置所有配置的複製通道
RESET SLAVE;
重置指定的通道
RESET SLAVE FOR CHANNEL 'master-1';
多源複製可以讓多個主節點同時並行進行復制到一個從節點上。一個slave為每個master建立一個複製通道。
至少需要兩臺主庫和一臺從庫。
多源複製中的主庫,可以配置成基於全域性事務標準(GTID)的複製,或者基於二進位制日誌的複製。
IP規劃
主庫01 192.168.174.201
主庫02 192.168.174.202
從庫 192.168.174.203
1. 在多源複製的從庫中,需要基於表的repositories,和基於檔案的repositories不相容。
在從庫上面操作
可以將下面引數新增到引數檔案中
master-info-repository=TABLE
relay-log-info-repository=TABLE
master_info_repository
決定包含master狀態和連線資訊的slave日誌,是以檔案格式(master.info),還是以表格式(mysql.slave_master_info)存在。
當沒有複製執行緒執行的時候,可以改變這個引數的值。
這個引數還會對sync_master_info系統引數有直接的影響。
relay_log_info_repository
這個引數決定寫到檔案(relay-log.info)或表(mysql.slave_relay_log_info)中的中繼日誌slave節點的位置。只有當沒有複製執行緒執行時,才可修改這個引數的值。
這個引數用於存放中繼日誌的資訊。預設是檔案格式,檔案的預設名是relay-log.info。
如果是TABLE格式,日誌資訊會寫到mysql.slave_relay_log_info。
動態修改,使用下面命令
STOP SLAVE;
SET GLOBAL master_info_repository = 'TABLE';
STOP SLAVE;
SET GLOBAL relay_log_info_repository = 'TABLE';
mysql> show global variables like '%repositor%';
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| master_info_repository | FILE |
| relay_log_info_repository | FILE |
+---------------------------+-------+
2 rows in set (0.03 sec)
mysql> SET GLOBAL master_info_repository = 'TABLE';
Query OK, 0 rows affected (0.00 sec)
mysql> SET GLOBAL relay_log_info_repository = 'TABLE';
ERROR 1766 (HY000): Unknown error 1766
Query OK, 0 rows affected, 1 warning (0.00 sec)
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| master_info_repository | TABLE |
| relay_log_info_repository | TABLE |
+---------------------------+-------+
2 rows in set (0.01 sec)
編輯從庫的其他配置檔案
[root@localhost 5505]# vim /mysql_data/cnf/my.cnf
# Log
server-id = 300
log-bin = /mysql_log/binlog/mysql-bin
relay-log = /mysql_log/binlog/product-relay-bin
relay-log-index = /mysql_log/binlog/product-relay-index
之後重啟資料庫,使得引數生效
[root@localhost install]# vim /etc/my.cnf
# Log
server-id = 100
log-bin = /log/binlog/mysql-bin
之後重啟資料庫,使得引數生效
建立複製使用者
mysql> grant replication slave on *.* to 'repl'@'192.168.174.%' identified by 'repl';
Query OK, 0 rows affected, 1 warning (0.06 sec)
+---------------+
| version() |
+---------------+
| 5.7.17-11-log |
+---------------+
1 row in set (0.00 sec)
主庫1
mysql> create database sale;
Query OK, 1 row affected (0.06 sec)
mysql> use sale;
Database changed
mysql> create table sale_record(id int);
Query OK, 0 rows affected (0.16 sec)
mysql> insert into sale_record values(10),(20);
Query OK, 2 rows affected (0.95 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.01 sec)
mysql> use market;
Database changed
mysql> create table market_record(id int)
-> ;
Query OK, 0 rows affected (0.04 sec)
Query OK, 2 rows affected (0.25 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.01 sec)
3. 備份主庫1和主庫2
主庫1
[root@MySQL01 mysql_software_57]# bin/mysqldump -uroot -p'root' -h 127.0.0.1 -q --single-transaction --master-data=2 -B sale > /tmp/20171211_sale.sql
主庫2
[root@localhost mysql_software_57]# bin/mysqldump -uroot -p'root' -S /mysql_data_57/mysql.sock -q --single-transaction --master-data=2 -B market > /tmp/20171211_market.sql
在從庫上面操作
[root@MySQL03 mysql_software_57]# bin/mysql -uroot -p'root' -h 127.0.0.1 < /tmp/20171211_sale.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@MySQL03 mysql_software_57]# bin/mysql -uroot -p'root' -h 127.0.0.1 < /tmp/20171211_market.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
搭建到主庫1的複製,將通道起名為master-1
mysql> change master to
-> master_host='192.168.174.201',
-> master_port=3306,
-> master_user='repl',
-> master_password='repl',
-> master_log_file='mysql-bin.000017',
-> master_log_pos=1209
-> FOR CHANNEL 'master-1';
Query OK, 0 rows affected, 1 warning (0.04 sec)
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.174.201
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000017
Read_Master_Log_Pos: 1209
Relay_Log_File: mysqld-relay-bin-master@002d1.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin.000017
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1209
Relay_Log_Space: 154
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
Master_UUID:
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name: master-1
Master_TLS_Version:
1 row in set (0.00 sec)
mysql> START SLAVE IO_THREAD FOR CHANNEL 'master-1';
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.01 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.174.201
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000017
Read_Master_Log_Pos: 1209
Relay_Log_File: mysqld-relay-bin-master@002d1.000002
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000017
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1209
Relay_Log_Space: 541
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 203fe772-177e-11e7-b15c-000c296b3b20
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
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name: master-1
Master_TLS_Version:
1 row in set (0.00 sec)
mysql> change master to
-> master_host='192.168.174.202',
-> master_port=3306,
-> master_user='repl',
-> master_password='repl',
-> master_log_file='mysql-bin.000014',
-> master_log_pos=1239
-> FOR CHANNEL 'master-2';
Query OK, 0 rows affected, 1 warning (0.02 sec)
mysql> START SLAVE IO_THREAD FOR CHANNEL 'master-2';
Query OK, 0 rows affected (0.00 sec)
mysql> START SLAVE SQL_THREAD FOR CHANNEL 'master-2';
Query OK, 0 rows affected (0.01 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.174.201
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000017
Read_Master_Log_Pos: 1481
Relay_Log_File: mysqld-relay-bin-master@002d1.000002
Relay_Log_Pos: 592
Relay_Master_Log_File: mysql-bin.000017
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1481
Relay_Log_Space: 813
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 203fe772-177e-11e7-b15c-000c296b3b20
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
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name: master-1
Master_TLS_Version:
*************************** 2. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.174.202
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000014
Read_Master_Log_Pos: 1239
Relay_Log_File: mysqld-relay-bin-master@002d2.000002
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000014
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1239
Relay_Log_Space: 541
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 2
Master_UUID: 2efd664c-177f-11e7-8323-000c29fcf2cd
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
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name: master-2
Master_TLS_Version:
2 rows in set (0.01 sec)
在主庫1上面插入資料
mysql> insert into sale_record values(30),(40),(50);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.01 sec)
mysql> insert into market_record values(300),(400),(500);
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.01 sec)
mysql> select * from sale.sale_record;
+------+
| id |
+------+
| 10 |
| 20 |
| 30 |
| 40 |
| 50 |
+------+
5 rows in set (0.00 sec)
+------+
| id |
+------+
| 100 |
| 200 |
| 300 |
| 400 |
| 500 |
+------+
5 rows in set (0.00 sec)
啟動多源複製
啟動所有配置的複製通道的IO執行緒
mysql> start slave io_thread;
Query OK, 0 rows affected (0.01 sec)
啟動所有配置的複製通道的SQL執行緒
Query OK, 0 rows affected (0.01 sec)
啟動指定的複製通道
mysql> start slave io_thread for channel 'master-1';
Query OK, 0 rows affected (0.00 sec)
停止多源複製
停止所有配置的複製通道的IO執行緒
mysql> stop slave io_thread;
Query OK, 0 rows affected (0.01 sec)
停止所有配置的複製通道的SQL執行緒
mysql> stop slave sql_thread;
Query OK, 0 rows affected (0.00 sec)
mysql> stop slave sql_thread for channel 'master-1';
Query OK, 0 rows affected, 1 warning (0.00 sec)
重置所有配置的複製通道
RESET SLAVE;
重置指定的通道
RESET SLAVE FOR CHANNEL 'master-1';
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2148570/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【Mysql】Mysql5.7的多源複製搭建MySql
- mysql 5.7多源複製MySql
- mysql 5.7 多主一從的多源複製搭建MySql
- MySQL 5.7 多主一從(多源複製)同步配置MySql
- MySQL5.7主從複製-半同步複製搭建MySql
- MySQL 多源複製MySql
- mysql 5.7 主從複製搭建及原理MySql
- MySQL 5.7.9的多源複製MySql
- MySQL 5.7 基於GTID搭建主從複製MySql
- MySQL 5.7 使用GTID方式搭建複製環境MySql
- MySQL 5.7並行複製MySql並行
- mysql 5.7半同步複製MySql
- MySQL 5.7 並行複製MySql並行
- [Mysql]Mysql5.7並行複製MySql並行
- 【Mysql】mysql5.7無損複製MySql
- mysql5.7主從複製,主主複製MySql
- Mysql5.7半同步複製MySql
- MySQL 5.7 延遲複製配置MySql
- MySQL5.7主從複製教程MySql
- mysql 5.7開啟並行複製MySql並行
- MySQL5.6 -> MySQL5.7 跨版本多源複製(Multi-Source Replication)MySql
- MySQL 5.7.9多源複製報錯修復MySql
- MySQL 5.7 複製的過濾引數MySql
- 【Mysql】mysql公開課之-mysql5.7複製特性MySql
- MySQL 5.7 多主複製報錯Coordinator stopped because there were error(s)MySqlError
- mysql主從複製搭建MySql
- MySQL 5.5 複製搭建流程MySql
- MySQL 5.7線上設定忽略表複製方法MySql
- MySQL Case-MySQL5.7無效的並行複製MySql並行
- #MySQL# mysql5.7新特性之半同步複製MySql
- mysql多源複製跳過錯誤處理方法MySql
- MySQL 複製介紹及搭建MySql
- MYSQL主從複製的搭建MySql
- MYSQL主主複製的搭建MySql
- MySQL案例07:MySQL5.7併發複製隱式bugMySql
- MySQL5.7半同步複製報錯案例分析MySql
- MySQL 5.7基於GTID的主從複製MySql
- MySQL 5.7組複製(group replication)的要求和限制MySql