国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > MySQL > 正文

MySQL 5.7創(chuàng)建多源復(fù)制

2024-07-24 12:32:41
字體:
供稿:網(wǎng)友
      MySQL 5.7版本支持多源復(fù)制,MySQL 5.5和5.6不支持。
      多源復(fù)制可以讓多個主節(jié)點同時并行進行復(fù)制到一個從節(jié)點上。一個slave為每個master創(chuàng)建一個復(fù)制通道。
       至少需要兩臺主庫和一臺從庫。
       多源復(fù)制中的主庫,可以配置成基于全局事務(wù)標(biāo)準(zhǔn)(GTID)的復(fù)制,或者基于二進制日志的復(fù)制。
 
       IP規(guī)劃
 
主庫01192.168.174.201
主庫02192.168.174.202
從庫192.168.174.203
 
1. 在多源復(fù)制的從庫中,需要基于表的repositories,和基于文件的repositories不兼容。
在從庫上面操作
可以將下面參數(shù)添加到參數(shù)文件中
master-info-repository=TABLE
relay-log-info-repository=TABLE
 
master_info_repository
決定包含master狀態(tài)和連接信息的slave日志,是以文件格式(master.info),還是以表格式(mysql.slave_master_info)存在。
當(dāng)沒有復(fù)制線程執(zhí)行的時候,可以改變這個參數(shù)的值。
這個參數(shù)還會對sync_master_info系統(tǒng)參數(shù)有直接的影響。
 
relay_log_info_repository
這個參數(shù)決定寫到文件(relay-log.info)或表(mysql.slave_relay_log_info)中的中繼日志slave節(jié)點的位置。只有當(dāng)沒有復(fù)制線程執(zhí)行時,才可修改這個參數(shù)的值。
這個參數(shù)用于存放中繼日志的信息。默認是文件格式,文件的默認名是relay-log.info。
如果是TABLE格式,日志信息會寫到mysql.slave_relay_log_info。
 
動態(tài)修改,使用下面命令
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
 
之后重啟數(shù)據(jù)庫,使得參數(shù)生效
 
2. 修改主庫1和主庫2參數(shù)文件,創(chuàng)建復(fù)制用戶,創(chuàng)建測試數(shù)據(jù)
編輯主庫的配置文件,注意,每個庫的server-id不能相同
[root@localhost install]# vim /etc/my.cnf
# Log
server-id = 100
log-bin = /log/binlog/mysql-bin
 
之后重啟數(shù)據(jù)庫,使得參數(shù)生效
 
創(chuàng)建復(fù)制用戶
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)
 
創(chuàng)建測試數(shù)據(jù)
主庫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上面的備份文件拷貝到從庫上面,進行恢復(fù)
在從庫上面操作
[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. 搭建多源復(fù)制
搭建到主庫1的復(fù)制,將通道起名為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)
 
啟動通道m(xù)aster-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)
 
啟動通道m(xù)aster-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上面插入數(shù)據(jù)
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上面插入數(shù)據(jù)
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)
常用命令
 
啟動多源復(fù)制
 
啟動所有配置的復(fù)制通道的IO線程
mysql> start slave io_thread;
Query OK, 0 rows affected (0.01 sec)
 
啟動所有配置的復(fù)制通道的SQL線程
mysql> start slave sql_thread;
Query OK, 0 rows affected (0.01 sec)
 
啟動指定的復(fù)制通道
mysql> start slave io_thread for channel 'master-1';
Query OK, 0 rows affected (0.00 sec)
 
停止多源復(fù)制
 
停止所有配置的復(fù)制通道的IO線程
mysql> stop slave io_thread;
Query OK, 0 rows affected (0.01 sec)
 
停止所有配置的復(fù)制通道的SQL線程
mysql> stop slave sql_thread;
Query OK, 0 rows affected (0.00 sec)
停止指定的復(fù)制通道
mysql> stop slave sql_thread for channel 'master-1';
Query OK, 0 rows affected, 1 warning (0.00 sec)
重置多源復(fù)制的從庫
 
重置所有配置的復(fù)制通道
RESET SLAVE;
 
重置指定的通道
RESET SLAVE FOR CHANNEL 'master-1';

(編輯:武林網(wǎng))

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 德惠市| 武强县| 新野县| 竹溪县| 分宜县| 沁源县| 梁河县| 宜章县| 乌兰察布市| 洱源县| 天镇县| 南涧| 吐鲁番市| 海阳市| 周口市| 榆林市| 礼泉县| 峨山| 宜阳县| 东丰县| 义乌市| 阜城县| 峨眉山市| 宜君县| 南川市| 麦盖提县| 阿拉善左旗| 吉木萨尔县| 阿瓦提县| 锡林郭勒盟| 堆龙德庆县| 枣庄市| 汶上县| 濮阳县| 饶平县| 娄底市| 托克托县| 鹤庆县| 杭锦旗| 莆田市| 精河县|