附註:

使用 OCI 將內部部署 MySQL Database 移轉至 Oracle HeatWave MySQL 受管理的執行處理 GoldenGate

簡介

Oracle Cloud Infrastructure GoldenGate (OCI GoldenGate) 是一項完全託管的服務,可協助資料工程師大規模即時將資料從一或多個資料管理系統移至 OCI 資料庫。在單一介面中設計、執行、協調及監控資料複製作業,無須配置或管理任何運算環境。OCI GoldenGate 支援數個來源和目標,包括 MySQL 和 Oracle HeatWave MySQL 資料庫服務。

在本教學課程中,我們將指導您如何使用 OCI GoldenGate 將內部部署 MySQL 資料庫移轉至 Oracle HeatWave MySQL 管理的執行處理。

目標

必要條件

限制

工作 1:建立來源和目標 MySQL 執行處理

作業 2:測試堡壘主機、內部部署和 Oracle Heatwave MySQL 執行處理之間的連線

  1. 在 OCI 堡壘主機上安裝 MySQL 從屬端和 MySQL Shell 公用程式。

  2. 測試從 OCI 堡壘主機至來源內部部署 MySQL 執行處理的連線。

    [root@bastion ~]#  mysql --host <sourceIP> -uadmin -p
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 15
    Server version: 5.7.44 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2025, Oracle and/or its affiliates.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    4 rows in set (0.00 sec)
    
    mysql> select @@version;
    +-----------+
    | @@version |
    +-----------+
    | 5.7.44    |
    +-----------+
    1 row in set (0.00 sec)
    
  3. 測試從來源內部部署 MySQL 到 Oracle Heatwave MySQL 管理執行處理的連線。

    [root@mysqlci57 ~]# mysql --host <targetIP> -u admin -p
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 108
    Server version: 8.4.4-u5-cloud MySQL Enterprise - Cloud
    
    Copyright (c) 2000, 2023, Oracle and/or its affiliates.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> select @@version;
    +----------------+
    | @@version      |
    +----------------+
    | 8.4.4-u5-cloud |
    +----------------+
    1 row in set (0.01 sec)
    

工作 3:建立 OCI GoldenGate 的使用者

作業 4:在 OCI GoldenGate 的來源資料庫中設定必要參數

如果目標為獨立 (非 HA),則不需要在來源上開啟 GTID。但如果目標是 HA,則強烈建議在來源上開啟 GTID。必須開啟 binlog 模式。

  1. 編輯 /etc/my.cnf 檔案並新增下列行。

    server-id=1
    log-bin=/var/log/mysql/mysql-bin.log
    max_binlog_size=100M
    binlog_format=ROW
    expire_logs_days=10
    -- binlog_row_metadata=FULL <-- this is not supported in Version 5.7.44. So DDL replication will not be possible if source is on v5.7.44.
    gtid_mode=ON
    enforce_gtid_consistency=ON
    
  2. 重新啟動 MySQL 伺服器。

    Systemctl stop mysqld
    Systemctl start mysqld
    Systemctl status mysqld
    

    如需完整的清單或參數,請檢查交易記錄設定與需求。如需詳細資訊,請參閱選項 B:在 OCI Compute 上使用您自己的堡壘主機

  3. 執行下列命令以檢查是否立即啟用二進位日誌。

    mysql> show binary logs;
    +------------------+-----------+
    | Log_name         | File_size |
    +------------------+-----------+
    | mysql-bin.000001 |       154 |
    +------------------+-----------+
    1 row in set (0.00 sec)
    
    mysql> show variables like 'bin%';
    +--------------------------------------------+--------------+
    | Variable_name                              | Value        |
    +--------------------------------------------+--------------+
    | bind_address                               | *            |
    | binlog_cache_size                          | 32768        |
    | binlog_checksum                            | CRC32        |
    | binlog_direct_non_transactional_updates    | OFF          |
    | binlog_error_action                        | ABORT_SERVER |
    | binlog_format                              | ROW          |
    | binlog_group_commit_sync_delay             | 0            |
    | binlog_group_commit_sync_no_delay_count    | 0            |
    | binlog_gtid_simple_recovery                | ON           |
    | binlog_max_flush_queue_time                | 0            |
    | binlog_order_commits                       | ON           |
    | binlog_row_image                           | FULL         |
    | binlog_rows_query_log_events               | OFF          |
    | binlog_stmt_cache_size                     | 32768        |
    | binlog_transaction_dependency_history_size | 25000        |
    | binlog_transaction_dependency_tracking     | COMMIT_ORDER |
    +--------------------------------------------+--------------+
    16 rows in set (0.01 sec)
    
  4. 執行下列指令以檢查 GTID 模式 (gtid_mode) 是否已開啟。

    mysql> show variables like 'gtid%';
    +----------------------------------+-----------+
    | Variable_name                    | Value     |
    +----------------------------------+-----------+
    | gtid_executed_compression_period | 1000      |
    | gtid_mode                        | ON        |   <--- it is now showing ON
    | gtid_next                        | AUTOMATIC |
    | gtid_owned                       |           |
    | gtid_purged                      |           |
    +----------------------------------+-----------+
    5 rows in set (0.00 sec)
    
    mysql> select @@gtid_executed, @@gtid_purged\G
    *************************** 1. row ***************************
    @@gtid_executed:
      @@gtid_purged:
    1 row in set, 1 warning (0.00 sec)
    
    mysql> select * from mysql.gtid_executed;
    Empty set (0.00 sec)   <--- this is empty because we just turned it ON. As transactions occur this will get populated
    

注意:第一個查詢通常會顯示 GTID 的 NULL 值。這是因為在 MySQL versions 5.7 中,GTID 值只會儲存在 mysql.gtid_executed 表格中。

工作 5:在目標資料庫中建立 airportdb 綱要 (僅限描述資料)

  1. 從來源資料庫擷取綱要描述資料。

    [root@bastion airport-db]# mysqldump --host <SourceIP> -u admin -p --no-data --routines --events airportdb > airportdb.sql
    mysqldump: [Warning] Using a password on the command line interface can be insecure.
    -- Warning: column statistics not supported by the server.
    
  2. 將綱要描述資料匯入目標資料庫。

    [root@bastion opc]#  mysql --host <TargetIP> -u admin -p
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 581
    Server version: 8.4.4-u5-cloud MySQL Enterprise - Cloud
    
    Copyright (c) 2000, 2025, Oracle and/or its affiliates.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> create database airportdb;
    Query OK, 1 row affected (0.01 sec)
    
    mysql> use airportdb;
    Database changed
    mysql> source airportdb.sql
    

工作 6:設定 OCI GoldenGate 部署並新增連線

關於如何設定 OCI GoldenGate 部署的幾個部落格和教學課程,因此我們將在此顯示幾個步驟。

  1. 登入 OCI 主控台並選取 GoldenGate 部署

  2. 按一下建立部署,然後輸入所需的資訊,如下圖所示。

    顯示如何建立黃金閘道部署的影像

  3. 建立部署頁面中新增來源和目標連線詳細資訊。

    顯示如何建立來源的黃金閘道連線的影像

    顯示如何為目標建立黃金閘道連線的影像

    顯示兩個 GG 中新增連線的影像

  4. 指定 OCI GoldenGate 部署的連線。按一下連線名稱,然後按一下指派部署

    顯示如何指定部署至連線的影像

    顯示指定至部署的來源連線影像

    顯示指定至部署的目標連線影像

  5. 使用 OCI 堡壘主機服務,設定連接埠轉送至連接埠 443,然後登入 OCI GoldenGate 主控台。

    顯示 goldengate 首頁 URL 的影像

  6. 從 OCI GoldenGate 主控台驗證資料庫連線。

    1. 按一下「漢堡」功能表,您將會在「任務 6.4」中看到兩個新增至部署的連線。

    2. 按一下連線以驗證連線。如果連線成功,您將看到按一下檢查點 + 來建立檢查點表格的選項。

      強烈建議您在 OCI 中使用 OCI GoldenGate 部署新增連線,因為連線會自動將 DNS 附加至 IP 位址,而不會透過這些 DNS,測試連線將會失敗。

      顯示黃金連線與測試連線的影像

任務 7:建立擷取與複製處理

  1. 建立 Extract 處理作業之前,請先確定來源資料庫中的 gtid_modeON ,特別是目標為 HA 時。

    新增 Extract 有兩種方法:

    • 方法 1:您可以在初始載入 (複製或傾印例項) 完成後新增 Extract,並使用精確的建立方法。如需詳細資訊,請參閱 Precise Instantiation for MySQL to MySQL Using MySQL Shell Utilities and Oracle GoldenGate

      若要新增 Extract 並啟動它,請從該特定 GTID 或 binlog 進行資料擷取,如下圖所示。Oracle 建議使用此方法。

      影像顯示 goldengate Extract 設定

      注意:此處的 GTID 集是從 dumpInstance 的 JSON 檔案或 copyInstance 命令的輸出取得。

    • 方法 2:您可以在開始初始資料載入之前,先在非常開頭新增 Extract,之後再將 Replicat 更改為以 dumpInstance() 的 JSON 檔案或 copyInstance() 輸出中顯示的特定 gtidexecuted/binlog# 和 binlog 位置為開頭。

      使用此方法使用 HANDLECOLLISION 參數,以避免發生任何重複的資料問題。

      備註:針對此 POC,已使用方法 2。

      編輯擷取參數檔:

      EXTRACT ext1
      USERIDALIAS  MySQLCI57, DOMAIN OracleGoldenGate
      EXTTRAIL e1
      --DDL INCLUDE MAPPED  (needed for DDL replication, also need to set  binlog_row_metadata to FULL in mysql config file on source db). But not supported for MySQL V5.7
      TRANLOGOPTIONS FETCHPARTIALJSON       (for JSON replication, also need to set binlog_row_value_options to empty string in the mysql config)
      TABLE airportdb.*;
      

      注意:如果您將 DDL INCLUDE MAPPED 新增至 Extract 參數檔,則會發生錯誤,表示 MySQL version 5.7.4 不支援 DDL 複製。

  2. 啟動 Extract 處理作業。

    顯示執行 goldengate Extract 的影像

  3. Extract 正在執行中並產生歷程檔,現在會建立 Replicat。

    1. 請先建立檢查點表格。移至組態段落,選取目標資料庫,然後按一下檢查點 + 以建立檢查點表格。

      顯示建立黃金檢查點表格的影像

    2. 建立 Replicat 處理作業。由於這是單向複寫,因此我們可以使用平行 Replicat 提升效能。若為雙向複製,只支援傳統 Replicat。

      不要啟動 Replicat 處理作業,只需建立即可。我們會在資料匯入後啟動。

      顯示建立黃金乘法複本的影像

    3. 編輯參數檔。您也可以新增 PARALLEL 參數,或使用預設併行執行。

      REPLICAT rep1
      USERIDALIAS  MySQLGG1, DOMAIN OracleGoldenGate
      MAP airportdb.*, TARGET airportdb.*;
      

工作 8:使用 copyInstance() 將資料從來源複製到目標

  1. 使用 copyInstance()dryRun:"true" 選項執行模擬測試。

    Type '\help' or '\?' for help; '\quit' to exit.
    MySQL  SQL > \connect admin@<Source IP>
    Creating a session to 'admin@<Source IP>'
    Fetching global names for auto-completion... Press ^C to stop.
    Your MySQL connection id is 37
    Server version: 5.7.44-log MySQL Community Server (GPL)
    No default schema selected; type \use <schema> to set one.
     MySQL  <Source IP>:3306 ssl  SQL > \js
    Switching to JavaScript mode...
     MySQL  <Source IP>:3306 ssl  JS > util.copyInstance('mysql://admin@<Target IP>', {"compatibility":["skip_invalid_accounts","strip_definers","strip_restricted_grants","strip_tablespaces","ignore_wildcard_grants","strip_invalid_grants","create_invisible_pks"], users:"true", threads:2, dryRun:"true"});
    Please provide the password for 'admin@<target IP': *******************
    Save password for 'admin@<target IP>'? [Y]es/[N]o/Ne[v]er (default No):
    
  2. 如果沒有錯誤,請移除 dryRun 選項,然後重新執行以執行資料載入。最終輸出應該如下:未報告任何錯誤

    SRC: Starting data dump
    100% (59.50M rows / ~59.36M rows), 142.25K rows/s, 9.68 MB/s
    SRC: Dump duration: 00:07:50s
    SRC: Total duration: 00:07:50s
    SRC: Schemas dumped: 2
    SRC: Tables dumped: 15
    SRC: Data size: 2.03 GB
    SRC: Rows written: 59502422
    SRC: Bytes written: 2.03 GB
    SRC: Average throughput: 4.33 MB/s
    1 thds indexing \ 100% (2.03 GB / 2.03 GB), 7.47 MB/s (161.06K rows/s), 15 / 15 tables done
    Building indexes - done
    Executing common postamble SQL - done
    TGT: 53 chunks (59.50M rows, 2.03 GB) for 15 tables in 2 schemas were loaded in 7 min 51 sec (avg throughput 4.32 MB/s, 126.29K rows/s)
    TGT: 17 DDL files were executed in 0 sec.
    TGT: 0 accounts were loaded, 3 accounts failed to load due to unsupported authentication plugin errors
    TGT: Data load duration: 7 min 51 sec
    TGT: 1 indexes were built in 0 sec.
    TGT: Total duration: 7 min 51 sec
    TGT: 0 warnings were reported during the load.
    ..
    ..
    Dump_metadata:
    Binlog_file: mysql-bin.000006
    Binlog_position: 626
    Executed_GTID_set: 7ee61c32-16eb-11f0-b3fc-02001702dcb5:1-3
    

注意:請記下 copyInstance() 輸出中所執行的 GTID,然後使用此項目來更改 Replicat。

作業 9:更改 Replicat 和開始

使用 000006 的日誌檔編號和 626 的日誌位置編號,如「工作 8」中 copyInstance() 的輸出所示。此日誌檔和日誌位置的格式應用於產生 CSN 000006:000000000000626

更改 Replicat,然後按一下啟動來啟動。 顯示如何更改 Replicat 的影像

Replicat 狀態顯示為執行中

顯示 Replicat 狀態的影像

注意:如果您已使用方法 1 來新增 Extract (如作業 7 所示),則不需要更改 Replicat。在此 POC 中,我們使用方法 2 來新增 Extract。兩種方法都可以正常運作。

作業 10:執行 DML 測試

在來源執行 DML 活動以測試複製。

確認

其他學習資源

docs.oracle.com/learn 上探索其他實驗室,或在 Oracle Learning YouTube 頻道上存取更多免費學習內容。此外,請造訪 education.oracle.com/learning-explorer 以成為 Oracle Learning Explorer。

如需產品文件,請造訪 Oracle Help Center