MariaDB上傳統複製升級爲GTID複製

在從庫查看複製狀態,注意複製延遲狀況,沒有延遲最好,有也沒有關係。mysql

SHOW SLAVE STATUS\G
- Relay_Master_Log_File: mysql-bin.000027
- Exec_Master_Log_Pos: 310094849
- Master_Log_File: mysql-bin.000027
- Read_Master_Log_Pos: 310094849

1. 在從庫執行命令,中止當前複製:sql

STOP SLAVE;

2. 查看並記錄中繼日誌執行的位置信息:bash

SHOW SLAVE STATUS\G
- Relay_Master_Log_File: mysql-bin.000027
- Exec_Master_Log_Pos: 310094849

3. 在主庫查看從庫執行位置對應的GTID位置日誌

SELECT BINLOG_GTID_POS('mysql-bin.000027', 300050472);
+------------------------------------------------+
| BINLOG_GTID_POS('mysql-bin.000027', 300050472) |
+------------------------------------------------+
| 192-1681233-35567846                           |
+------------------------------------------------+

4. 回到從庫設置GTID的開始位置,即第三步中從主庫查詢到的位置信息code

SET GLOBAL gtid_slave_pos = '192-1681233-35567846';

5. 從新設置主庫信息ip

CHANGE MASTER TO MASTER_HOST='192.168.1.233', # 主機
                 MASTER_PORT=3306,            # 端口
                 MASTER_USER='replicator',    # 用戶
                 MASTER_PASSWORD='replpass',  # 密碼
                 MASTER_USE_GTID=slave_pos;   # 位置

6. 啓動複製it

START SLAVE;

7. 查看複製狀態io

SHOW SLAVE STATUS\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.1.233
                  Master_User: replicate
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000027
          Read_Master_Log_Pos: 310094849
               Relay_Log_File: relay-bin.000002
                Relay_Log_Pos: 10045104
        Relay_Master_Log_File: mysql-bin.000027
             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: 310094849
              Relay_Log_Space: 10045407
              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: 1681233
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
                   Using_Gtid: Slave_Pos
                  Gtid_IO_Pos: 192-1681233-35580793
      Replicate_Do_Domain_Ids: 
  Replicate_Ignore_Domain_Ids: 
                Parallel_Mode: optimistic
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it

能夠看到Using_Gtid有值,Gtid_IO_Pos也在不停變化。至此,傳統複製已經更改爲GTID複製。event

相關文章
相關標籤/搜索