附註:
- 此教學課程需要存取 Oracle Cloud。若要註冊免費帳戶,請參閱開始使用 Oracle Cloud Infrastructure Free Tier 。
- 其使用 Oracle Cloud Infrastructure 證明資料、租用戶以及區間的範例值。完成實驗室時,請將這些值替代為雲端環境特定的值。
使用 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 管理的執行處理。
目標
- 使用 OCI GoldenGate,將內部部署 MySQL 資料庫移轉至 OCI 上的 Oracle HeatWave MySQL 管理執行處理。
必要條件
-
來源 MySQL 資料庫為內部部署資料庫,目標為 Oracle Heatwave MySQL 管理的執行處理,並已備妥 OCI Bastion 主機。
-
這是單向複寫,因此目標的版本可以高於來源。如果是雙向複寫,建議使用相同版本的來源和目標。
-
來源上必須啟用
log_bin
(binlog)。 -
來源和目標執行處理上的
binlog_expire_logs_second
執行處理參數必須至少設為 72 小時。 -
來源和目標執行處理上的
binlog_row_metadata
執行處理參數必須設為完整,才能允許複製資料定義語言 (DDL)。注意:在此教學課程中,來源正在執行 MySQL 版本
5.7.44
,其中不支援binlog_row_metadata
參數。因此,不支援 DDL 複製。 -
如果目標 Oracle Heatwave MySQL 執行處理有高可用性 (HA),則全域交易 ID (GTID) 模式必須位於來源上,否則為選擇性模式。
-
複查支援的資料類型。如需詳細資訊,請參閱 MySQL:支援的資料類型、物件及作業。
-
複查 DDL 複製限制。如需詳細資訊,請參閱使用 DDL 複製。
-
應使用下列其中一種方法,從來源提前建立目標執行處理:
- 方法 1:使用 MySQL shell 公用程式,例如
util.dumpInstance
和util.loadDump
。 - 方法 2:使用 MySQL shell 公用程式 (例如
util.copyInstance
)。 - 方法 3:使用 OCI GoldenGate 進行初始 Extract 和 Replicat,以執行初始資料載入。
注意:在本教學課程中,我們將使用
util.copyInstance
進行初始載入。 - 方法 1:使用 MySQL shell 公用程式,例如
-
OCI 中已安裝 MySQL 從屬端和 MySQL Shell 公用程式的 OCI 堡壘主機。
-
FastConnect/IPSec/VPN、輸入規則和更新的安全清單,以允許在內部部署來源、目標 Oracle Heatwave MySQL、堡壘主機和 OCI GoldenGate 之間進行通訊。
限制
-
自動遞增資料欄問題。
-
如果表格有一個資料欄,但不是主索引鍵或唯一索引鍵,則對應會失敗,因為該表格之所有資料欄的組合在來源和目標上都相同。
-
資料類型、DDL 及其他功能限制。
-
使用「作用中 - 作用中」複製時,這兩個系統上的時區必須相同,才能運作時戳式衝突解決和偵測。
工作 1:建立來源和目標 MySQL 執行處理
-
來源:
-On-premise Hostname: MySQLCI57 OEL 7.9 MySQL version 5.7.44 Intel Hardware Standard.Flex3 with 4 CPUs and 32GB Dedicated VM
-
目標:
-OCI Oracle Heatwave MySQL Managed Instance Hostname: MySQLGG1 with HA and no heatwave (4CPU and 32GB) OEL 8 with latest build MySQL version: 8.4.4 Private subnet
-
OCI 堡壘主機:
-OCI Hostname: Bastion OEL 8 with Intel hardware Standard.Flex3 with 4CPUs and 32GB
作業 2:測試堡壘主機、內部部署和 Oracle Heatwave MySQL 執行處理之間的連線
-
在 OCI 堡壘主機上安裝 MySQL 從屬端和 MySQL Shell 公用程式。
-
測試從 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)
-
測試從來源內部部署 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 的使用者
-
來源:
create user 'ggsuser_S'@'%' identified by "<password>"; grant all privileges on airportdb.* to 'ggsuser_S'@'%' with grant option; Grant select, process, replication slave, reload, replication client on *.* to 'ggsuser_S'@'%';
-
目標:
create user 'ggsuser_T'@'%' identified by "<password>"; grant all privileges on airportdb.* to 'ggsuser_T'@'%' with grant option; Grant select, process, replication slave, replication client on *.* to 'ggsuser_T'@'%'; Create database ggadmin; -- you create this db on target side to store the checkpoint table. grant all privileges on ggadmin.* to 'ggsuser_T'@'%' with grant option;
作業 4:在 OCI GoldenGate 的來源資料庫中設定必要參數
如果目標為獨立 (非 HA),則不需要在來源上開啟 GTID。但如果目標是 HA,則強烈建議在來源上開啟 GTID。必須開啟 binlog
模式。
-
編輯
/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
-
重新啟動 MySQL 伺服器。
Systemctl stop mysqld Systemctl start mysqld Systemctl status mysqld
如需完整的清單或參數,請檢查交易記錄設定與需求。如需詳細資訊,請參閱選項 B:在 OCI Compute 上使用您自己的堡壘主機。
-
執行下列命令以檢查是否立即啟用二進位日誌。
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)
-
執行下列指令以檢查 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
綱要 (僅限描述資料)
-
從來源資料庫擷取綱要描述資料。
[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.
-
將綱要描述資料匯入目標資料庫。
[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 部署的幾個部落格和教學課程,因此我們將在此顯示幾個步驟。
-
登入 OCI 主控台並選取 GoldenGate 部署。
-
按一下建立部署,然後輸入所需的資訊,如下圖所示。
-
在建立部署頁面中新增來源和目標連線詳細資訊。
-
指定 OCI GoldenGate 部署的連線。按一下連線名稱,然後按一下指派部署。
-
使用 OCI 堡壘主機服務,設定連接埠轉送至連接埠
443
,然後登入 OCI GoldenGate 主控台。 -
從 OCI GoldenGate 主控台驗證資料庫連線。
-
按一下「漢堡」功能表,您將會在「任務 6.4」中看到兩個新增至部署的連線。
-
按一下連線以驗證連線。如果連線成功,您將看到按一下檢查點 + 來建立檢查點表格的選項。
強烈建議您在 OCI 中使用 OCI GoldenGate 部署新增連線,因為連線會自動將 DNS 附加至 IP 位址,而不會透過這些 DNS,測試連線將會失敗。
-
任務 7:建立擷取與複製處理
-
建立 Extract 處理作業之前,請先確定來源資料庫中的
gtid_mode
為 ON ,特別是目標為 HA 時。新增 Extract 有兩種方法:
-
方法 1:您可以在初始載入 (複製或傾印例項) 完成後新增 Extract,並使用精確的建立方法。如需詳細資訊,請參閱 Precise Instantiation for MySQL to MySQL Using MySQL Shell Utilities and Oracle GoldenGate 。
若要新增 Extract 並啟動它,請從該特定 GTID 或 binlog 進行資料擷取,如下圖所示。Oracle 建議使用此方法。
注意:此處的 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 參數檔,則會發生錯誤,表示 MySQLversion 5.7.4
不支援 DDL 複製。
-
-
啟動 Extract 處理作業。
-
Extract 正在執行中並產生歷程檔,現在會建立 Replicat。
-
請先建立檢查點表格。移至組態段落,選取目標資料庫,然後按一下檢查點 + 以建立檢查點表格。
-
建立 Replicat 處理作業。由於這是單向複寫,因此我們可以使用平行 Replicat 提升效能。若為雙向複製,只支援傳統 Replicat。
不要啟動 Replicat 處理作業,只需建立即可。我們會在資料匯入後啟動。
-
編輯參數檔。您也可以新增
PARALLEL
參數,或使用預設併行執行。REPLICAT rep1 USERIDALIAS MySQLGG1, DOMAIN OracleGoldenGate MAP airportdb.*, TARGET airportdb.*;
-
工作 8:使用 copyInstance()
將資料從來源複製到目標
-
使用
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):
-
如果沒有錯誤,請移除
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 狀態顯示為執行中。
注意:如果您已使用方法 1 來新增 Extract (如作業 7 所示),則不需要更改 Replicat。在此 POC 中,我們使用方法 2 來新增 Extract。兩種方法都可以正常運作。
作業 10:執行 DML 測試
在來源執行 DML 活動以測試複製。
-
來源:
mysql> select count(*) from passenger; +----------+ | count(*) | +----------+ | 36095 | +----------+ 1 row in set (0.01 sec) mysql> insert into passenger (passportno,firstname,lastname) values ('Pd89UKL','Timothy','London'); Query OK, 1 row affected (0.00 sec) mysql> commit -> ; Query OK, 0 rows affected (0.00 sec) mysql> select count(*) from passenger; +----------+ | count(*) | +----------+ | 36096 | +----------+ 1 row in set (0.00 sec) mysql> select @@version; +------------+ | @@version | +------------+ | 5.7.44-log | +------------+ 1 row in set (0.00 sec)
-
目標:
[root@bastion opc]# mysql --host <target IP> -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 1249 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> use airportdb; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select count(*) from passenger; +----------+ | count(*) | +----------+ | 36096 | +----------+ 1 row in set (0.00 sec) mysql> select @@version -> ; +----------------+ | @@version | +----------------+ | 8.4.4-u5-cloud | +----------------+ 1 row in set (0.00 sec)
相關連結
確認
- 作者 - Chakradhar Jagganagari (提升導入專家 - 資料庫)
其他學習資源
在 docs.oracle.com/learn 上探索其他實驗室,或在 Oracle Learning YouTube 頻道上存取更多免費學習內容。此外,請造訪 education.oracle.com/learning-explorer 以成為 Oracle Learning Explorer。
如需產品文件,請造訪 Oracle Help Center 。
Migrate On-Premises MySQL Database to Oracle HeatWave MySQL Managed Instance using OCI GoldenGate
G34897-01
Copyright ©2025, Oracle and/or its affiliates.