MySQL5.7.19-レプリケーションのオンライン変更-ログからトランザクションへ


【事前説明】
  • MasterとSlaveは並列に動作する必要があります.すなわち、MasterとSlaveの最初のステップが完了した後、第2のステップを実行することができます.
  • ステップ毎に、Masterを先に実行するかSlaveを先に実行するかは、要求されていない.

  • 【Master - Lebron - 192.168.1.122】
    Masterバージョンが5.7.6より大きいかどうかを確認します.
    mysql> show variables like 'version';
    +---------------+------------+
    | Variable_name | Value      |
    +---------------+------------+
    | version       | 5.7.19-log |
    +---------------+------------+
    1 row in set (0.00 sec)

    Masterのgtid_をチェックmodeがoffかどうか
    mysql> show variables like 'gtid_mode';
    +---------------+-------+
    | Variable_name | Value |
    +---------------+-------+
    | gtid_mode     | OFF   |
    +---------------+-------+
    1 row in set (0.00 sec)

    最初のステップ
    mysql> set @@global.enforce_gtid_consistency=warn;
    Query OK, 0 rows affected (0.00 sec)
  • mysqlを終了し、エラーログを表示し、エラーがないことを確認します.
    mysql> quit
    Bye
    [root@lebron sysconfig]# tail -f /var/log/mysqld.log
    Version: '5.7.19-log'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server (GPL)
    2017-12-10T15:29:40.557075Z 0 [Note] Executing 'SELECT * FROM INFORMATION_SCHEMA.TABLES;' to get a list of tables using the deprecated partition engine. You may use the startup option '--disable-partition-engine-check' to skip this check. 
    2017-12-10T15:29:40.557077Z 0 [Note] Beginning of list of non-natively partitioned tables
    2017-12-10T15:29:40.564129Z 0 [Note] End of list of non-natively partitioned tables
    2017-12-10T15:29:41.171276Z 3 [Note] Access denied for user 'UNKNOWN_MYSQL_USER'@'localhost' (using password: NO)
    2017-12-10T17:20:10.601941Z 6 [Warning] IP address '192.168.1.123' could not be resolved: Name or service not known
    2017-12-10T17:34:27.796701Z 10 [Note] Start binlog_dump to master_thread_id(10) slave_server(100), pos(mysql-bin.000001, 154)
    2017-12-10T17:39:27.813157Z 11 [Note] While initializing dump thread for slave with UUID , found a zombie dump thread with the same UUID. Master is killing the zombie dump thread(10).
    2017-12-10T17:39:27.813305Z 11 [Note] Start binlog_dump to master_thread_id(11) slave_server(100), pos(mysql-bin.000001, 154)
    2017-12-10T19:01:14.798790Z 12 [Note] Changed ENFORCE_GTID_CONSISTENCY from OFF to WARN.

    ステップ2
    mysql> set @@global.enforce_gtid_consistency=on;
    Query OK, 0 rows affected (0.00 sec)

    ステップ3
    mysql> set @@global.gtid_mode=off_permissive;
    Query OK, 0 rows affected (0.02 sec)
  • mysqlを終了し、エラーログを表示し、エラーがないことを確認します.
    mysql> quit
    Bye
    [root@lebron sysconfig]# tail -f /var/log/mysqld.log
    2017-12-10T15:29:40.557077Z 0 [Note] Beginning of list of non-natively partitioned tables
    2017-12-10T15:29:40.564129Z 0 [Note] End of list of non-natively partitioned tables
    2017-12-10T15:29:41.171276Z 3 [Note] Access denied for user 'UNKNOWN_MYSQL_USER'@'localhost' (using password: NO)
    2017-12-10T17:20:10.601941Z 6 [Warning] IP address '192.168.1.123' could not be resolved: Name or service not known
    2017-12-10T17:34:27.796701Z 10 [Note] Start binlog_dump to master_thread_id(10) slave_server(100), pos(mysql-bin.000001, 154)
    2017-12-10T17:39:27.813157Z 11 [Note] While initializing dump thread for slave with UUID , found a zombie dump thread with the same UUID. Master is killing the zombie dump thread(10).
    2017-12-10T17:39:27.813305Z 11 [Note] Start binlog_dump to master_thread_id(11) slave_server(100), pos(mysql-bin.000001, 154)
    2017-12-10T19:01:14.798790Z 12 [Note] Changed ENFORCE_GTID_CONSISTENCY from OFF to WARN.
    2017-12-10T19:05:50.369256Z 13 [Note] Changed ENFORCE_GTID_CONSISTENCY from WARN to ON.
    2017-12-10T19:09:01.626528Z 13 [Note] Changed GTID_MODE from OFF to OFF_PERMISSIVE.

    ステップ4
    mysql> set @@global.gtid_mode=on_permissive;
    Query OK, 0 rows affected (0.02 sec)
  • 設定結果を表示
  • mysql> show variables like 'gtid_mode';
    +---------------+---------------+
    | Variable_name | Value         |
    +---------------+---------------+
    | gtid_mode     | ON_PERMISSIVE |
    +---------------+---------------+
    1 row in set (0.00 sec)

    ステップ5-Masterは操作せず、Slaveでログベースのコピーが完了したかどうかを確認します.
    ステップ6
    mysql> set @@global.gtid_mode=on;
    Query OK, 0 rows affected (0.02 sec)

    ステップ7~10-Masterに操作なし
    【Slave - Kyrie - 192.168.1.123】
    Slaveバージョンが5.7.6より大きいかどうかを確認します.
    mysql> show variables like 'version';
    +---------------+------------+
    | Variable_name | Value      |
    +---------------+------------+
    | version       | 5.7.19-log |
    +---------------+------------+
    1 row in set (0.00 sec)

    Slaveのgtid_をチェックmodeがoffかどうか
    mysql> show variables like 'gtid_mode';
    +---------------+-------+
    | Variable_name | Value |
    +---------------+-------+
    | gtid_mode     | OFF   |
    +---------------+-------+
    1 row in set (0.00 sec)

    最初のステップ
    mysql> set @@global.enforce_gtid_consistency=warn;
    Query OK, 0 rows affected (0.00 sec)

    ステップ2
    mysql> set @@global.enforce_gtid_consistency=on;
    Query OK, 0 rows affected (0.00 sec)

    ステップ3
    mysql> set @@global.gtid_mode=off_permissive;
    Query OK, 0 rows affected (0.02 sec)
  • mysqlを終了し、エラーログを表示し、エラーがないことを確認します.
    mysql> quit
    Bye
    [root@lebron sysconfig]# tail -f /var/log/mysqld.log
    2017-12-10T15:29:40.557077Z 0 [Note] Beginning of list of non-natively partitioned tables
    2017-12-10T15:29:40.564129Z 0 [Note] End of list of non-natively partitioned tables
    2017-12-10T15:29:41.171276Z 3 [Note] Access denied for user 'UNKNOWN_MYSQL_USER'@'localhost' (using password: NO)
    2017-12-10T17:20:10.601941Z 6 [Warning] IP address '192.168.1.123' could not be resolved: Name or service not known
    2017-12-10T17:34:27.796701Z 10 [Note] Start binlog_dump to master_thread_id(10) slave_server(100), pos(mysql-bin.000001, 154)
    2017-12-10T17:39:27.813157Z 11 [Note] While initializing dump thread for slave with UUID , found a zombie dump thread with the same UUID. Master is killing the zombie dump thread(10).
    2017-12-10T17:39:27.813305Z 11 [Note] Start binlog_dump to master_thread_id(11) slave_server(100), pos(mysql-bin.000001, 154)
    2017-12-10T19:01:14.798790Z 12 [Note] Changed ENFORCE_GTID_CONSISTENCY from OFF to WARN.
    2017-12-10T19:05:50.369256Z 13 [Note] Changed ENFORCE_GTID_CONSISTENCY from WARN to ON.
    2017-12-10T19:09:01.626528Z 13 [Note] Changed GTID_MODE from OFF to OFF_PERMISSIVE.

    ステップ4
    mysql> set @@global.gtid_mode=on_permissive;
    Query OK, 0 rows affected (0.02 sec)
  • 設定結果を表示
  • mysql> show variables like 'gtid_mode';
    +---------------+---------------+
    | Variable_name | Value         |
    +---------------+---------------+
    | gtid_mode     | ON_PERMISSIVE |
    +---------------+---------------+
    1 row in set (0.00 sec)

    ステップ5-MasterのデータがSlaveに同期しているかどうかを確認し、Emptyは同期していることを示します.
  • 匿名レプリケーション、すなわちgtid以外のすべてのレプリケーション、すなわちログベースのレプリケーション.
  • 結果が空でない場合、結果が空になるまで操作を続行します.
  • mysql> show status like 'ongoing_anonymouse_transaction_count';
    Empty set (0.00 sec)

    ステップ6
    mysql> set @@global.gtid_mode=on;
    Query OK, 0 rows affected (0.02 sec)

    ステップ7
    mysql> stop slave;
    Query OK, 0 rows affected (0.01 sec)

    ステップ8
    mysql> change master to master_auto_position=1;
    Query OK, 0 rows affected (0.01 sec)

    ステップ9
    mysql> start slave;
    Query OK, 0 rows affected (0.01 sec)

    ステップ10
  • マスタースレーブ間で同期が発生した場合、Retrieved_Gtid_Set & Executed_Gtid_Setこそ価値がある.
  • mysql> show slave status\G;
    *************************** 1. row ***************************
                   Slave_IO_State: Waiting for master to send event
                      Master_Host: 192.168.1.122
                      Master_User: lxl
                      Master_Port: 3306
                    Connect_Retry: 60
                  Master_Log_File: mysql-bin.000004
              Read_Master_Log_Pos: 420
                   Relay_Log_File: lebron-relay-bin.000002
                    Relay_Log_Pos: 633
            Relay_Master_Log_File: mysql-bin.000004
                 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: 420
                  Relay_Log_Space: 841
                  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: a41e6957-dc02-11e7-a9aa-0800271c6804
                 Master_Info_File: /var/lib/mysql/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: a41e6957-dc02-11e7-a9aa-0800271c6804:1
                Executed_Gtid_Set: a41e6957-dc02-11e7-a9aa-0800271c6804:1
                    Auto_Position: 1
             Replicate_Rewrite_DB: 
                     Channel_Name: 
               Master_TLS_Version: 
    1 row in set (0.00 sec)
    
    ERROR: 
    No query specified

    に注意
    global.enforce_gtid_consistency=on & global.gtid_mode=onをmyに設定します.cnfでは,次回サービスを開始するとgtid方式でレプリケーションが完了する.