為何在我使用 MySQL 作為來源時,AWS DMS CDC 任務會因「Error 1236」而失敗?
我使用 AWS Database Migration Service (AWS DMS) 將資料從來源 MySQL 資料庫引擎遷移至目標引擎。然而,變更資料擷取 (CDC) 任務失敗,並顯示「Error 1236」。
簡短描述
透過 AWS DMS,您可以執行一次性遷移,並複寫持續變更以保持來源與目標同步。為了從來源資料庫讀取持續變更,AWS DMS 會使用引擎專屬的 API 動作來讀取來源引擎的交易日誌。當您使用 MySQL 作為來源時,AWS DMS 會從資料列型二進位日誌 (binlog) 讀取變更。接著,AWS DMS 會將這些變更遷移至目標。
如果二進位日誌發生問題,您就會收到「Error 1236」訊息。當您使用自我管理或 AWS 受管 MySQL 相容版資料庫時,請確認您已正確設定所有二進位記錄參數,以支援 AWS DMS CDC。
解決方法
若要對「Error 1236」進行疑難排解,請依據您收到的錯誤訊息採取以下動作。
「Could not find first log file name in binary log index file reading binlog」
來自任務日誌的錯誤範例:
[SOURCE_CAPTURE ]I: Setting position in binlog 'mysql-bin-changelog.014448' at 119624570 (mysql_endpoint_capture.c:886) [SOURCE_CAPTURE ]I: Position was set in binlog 'mysql-bin-changelog.014448' at 119624570 (mysql_endpoint_capture.c:922) [SOURCE_CAPTURE ]E: Error 1236 (Could not find first log file name in binary log index file) reading binlog [1020493] [TASK_MANAGER ]I: Task - ABCDXXXXXXXXXXXXXX is in ERROR state, updating starting status to AR_NOT_APPLICABLE
上述錯誤會在來源 MySQL 資料庫移除了 AWS DMS 用來將資料變更複寫至目標的二進位日誌時發生。MySQL 可能基於以下原因移除二進位日誌:
- 二進位日誌保留期間設定過低。
- AWS DMS 任務因為問題而卡住或停止。
若要確認二進位日誌是否可用,請執行以下命令以列出所有二進位日誌檔案:
mysql> SHOW BINARY LOGS;
接著,請執行以下命令以列出目前的二進位日誌檔案與位置:
mysql> SHOW MASTER STATUS;
如需上述命令的更多資訊,請參閱 MySQL 網站上的 SHOW BINARY LOGS 陳述式與 SHOW MASTER STATUS 陳述式。
若要解決此錯誤,請檢查來源 MySQL 資料庫上的二進位日誌保留期間。如有需要,請延長保留期間。重新啟動 AWS DMS 任務,以再次執行完整載入階段。
請依據您的資料庫類型採取以下動作。
自我管理的 MySQL 資料庫
若要檢查內部部署或 Amazon Elastic Compute Cloud (Amazon EC2) 的二進位日誌保留期間,請檢視 expire_logs_days 的值。如需更多資訊,請參閱 MySQL 網站上的日誌過期天數。
**注意:**最佳實務是將 SET 變數的全域參數值設定為 1 或更大的值。如需更多資訊,請參閱 MySQL 網站上的 SET 變數指派語法。
AWS 受管 MySQL 資料庫
請檢查 Amazon Relational Database Service (Amazon RDS) for MySQL 或 Amazon Aurora MySQL 相容版本資料庫上設定的二進位日誌保留時數。請執行以下命令:
mysql> call mysql.rds_show_configuration;
若要將日誌保留時間提高至 24 小時,請執行以下命令:
mysql> call mysql.rds_set_configuration('binlog retention hours', 24);
「Log event entry exceeded max_allowed_packet; increase max_allowed_packet on master...」
來自任務日誌的錯誤範例:
[SOURCE_CAPTURE ]I: Position was set in binlog 'mysql-bin.056367' at 787323674 (mysql_endpoint_capture.c:922) [SOURCE_CAPTURE ]D: net_safe_read error 1236 (log event entry exceeded max_allowed_packet; Increase max_allowed_packet on master; the first event 'mysql-bin.056367' at 787323674, the last event read from '/mnt/data/logs/mysql-bin.056367' at 123, the last byte read from '/mnt/data/logs/mysql-bin.056367' at 787323693.) (mysql_endpoint_capture.c:1119) [SOURCE_CAPTURE ]I: Error 1236 (log event entry exceeded max_allowed_packet; Increase max_allowed_packet on master; the first event 'mysql-bin.056367' at 787323674, the last event read from '/mnt/data/logs/mysql-bin.056367' at 123, the last byte read from '/mnt/data/logs/mysql-bin.056367' at 787323693.) reading binlog. Try reconnect (mysql_endpoint_capture.c:1123)
可能發生上述錯誤的原因如下:
- 某個資料列的資料量超過來源上 max_allowed_packet 的值。如需更多資訊,請參閱 MySQL 網站上的最大允許封包大小。
- 單一交易包含大量資料,或單一交易中包含多個資料列更新。
- 來源資料庫的二進位日誌發生毀損。
如果您使用二進位大型物件 (BLOB) 欄位或長字串,請將 max_allowed_packet 的值設定為您所使用的最大 BLOB。此參數的值最大可達 1 GB。如需更多資訊,請參閱 MySQL 網站上的 BLOB 與 TEXT 類型。
若要查看最大交易的大小,請檢視您的二進位日誌。請確認交易大小未超過 max_allowed_packet 的大小。如需了解如何拆分大型交易,請參閱 MySQL 網站上的封包過大。
如果您仍遇到此錯誤,則來源二進位日誌中可能存在毀損。
若要確認二進位日誌是否有問題,請完成以下步驟:
-
請執行以下命令以確認二進位日誌是否存在:
mysql> SHOW BINARY LOGS; -
若要查看二進位日誌中的事件,請執行以下命令:
mysql> SHOW BINLOG EVENTS IN 'binlog file' FROM position;**注意:**請將 binlog 檔案替換為二進位日誌名稱,並將 position 替換為事件發生的位置。
-
若要下載二進位日誌,請執行以下命令:
shell> mysqlbinlog \ --read-from-remote-server \ --host=MySQLInstance1.cg034hpkmmjt.region.rds.amazonaws.com \ --port=3306 \ --user ReplUser \ --password \ --raw \ --verbose \ --result-file=/tmp/ \ binlog.00098 -
請檢查錯誤訊息中提及的二進位日誌是否發生毀損。
-
如果二進位日誌已毀損,請建立 AWS Support 案例。
「Binlog truncated in the middle of event; consider out of disk space on master...」
來自任務日誌的錯誤範例:
[SOURCE_CAPTURE ]I: Read next binary log event failed; net_safe_read error 1236 (binlog truncated in the middle of event; consider out of disk space on master; the first event 'mysql-bin-changelog.017672' at 486, the last event read from '/rdsdbdata/log/binlog/mysql-bin-changelog.017672' at 125, the last byte read from '/rdsdbdata/log/binlog/mysql-bin-changelog.017672' at 4756.) (mysql_endpoint_capture.c:1069) [SORTER ]I: Transaction consistency reached (sorter_transaction.c:347) [TASK_MANAGER ]I: Starting replication now (replicationtask.c:2774) [TASK_MANAGER ]I: Task - MGLVRIRUJH6FE2GP6F7SW46BPBW6YKF2JUJPSVY is in RUNNING state, updating starting status to AR_RUNNING (repository.c:5110)
可能發生上述錯誤的原因如下:
- 主要伺服器上的 sync_binlog != 1。這表示二進位日誌事件可能未在磁碟上同步。如需更多資訊,請參閱 MySQL 網站上的同步 binlog。
- 來源資料庫的二進位日誌發生毀損。
若要解決此錯誤,請確認來源上的 sync_binlog 參數值已設定為 1。接著,重新啟動任務。
如果 sync_binlog 參數已設定為 1,請檢視二進位日誌是否發生毀損。如需相關指示,請參閱前述的**「Log event entry exceeded max_allowed_packet; increase max_allowed_packet on master...」**章節。
「Client requested master to start replication from impossible position」
來自任務日誌的錯誤範例:
[SOURCE_CAPTURE ]I: Position was set in binlog 'mysql-bin-changelog.007989' at 1631 (mysql_endpoint_capture.c:922) [SOURCE_CAPTURE ]I: Read next binary log event failed; net_safe_read error 1236 (Client requested master to start replication from impossible position; the first event 'mysql-bin-changelog.007989' at 1631, the last event read from 'mysql-bin-changelog.007989' at 4, the last byte read from 'mysql-bin-changelog.007989' at 4.) (mysql_endpoint_capture.c:1053) [SOURCE_CAPTURE ]D: Error reading binary log. [1020493] (mysql_endpoint_capture.c:3995) [SOURCE_CAPTURE ]E: Error 1236 (Client requested master to start replication from impossible position; the first event 'mysql-bin-changelog.007989' at 1631, the last event read from 'mysql-bin-changelog.007989' at 4, the last byte read from 'mysql-bin-changelog.007989' at 4.) reading binlog events [1020493] (mysql_endpoint_capture.c:1074)
此錯誤發生於來源 MySQL 資料庫伺服器意外停止時。意外停止可能因硬體故障而發生,例如磁碟錯誤或電力中斷。
若要解決此錯誤,請依據 AWS DMS 任務類型採取以下其中一項動作:
- 對於完整載入與 CDC 任務,請重新啟動 AWS DMS 任務。
- 對於僅限 CDC 的任務,請從下一個二進位日誌位置啟動 AWS DMS 任務。
「Client requested master to start replication from position > file size」
來自任務日誌的錯誤範例:
[SOURCE_CAPTURE ]I: Position was set in binlog 'binlog.000012' at 2179 (mysql_endpoint_capture.c:922) [SOURCE_CAPTURE ]I: Read next binary log event failed; net_safe_read error 1236 (Client requested master to start replication from position > file size) (mysql_endpoint_capture.c:1052
此錯誤可能因為二進位日誌加密而發生。如果您的來源 MySQL 資料庫執行 MySQL 8.0 版本,且您已加密二進位日誌,則 AWS DMS 無法在任務初始化時讀取日誌。因此,AWS DMS 會記錄此錯誤。當您啟用二進位日誌加密時,就無法使用以 MySQL 8.0 作為來源的 CDC 複寫。如需更多資訊,請參閱 MySQL 網站上的加密二進位日誌檔案與轉送日誌檔案。
若要解決此問題,請完成以下步驟:
-
請執行以下命令以檢查您的 MySQL 版本:
mysql> SELECT VERSION(); -
請執行以下命令以檢查 binlog_encryption 是否為開啟:
mysql> SELECT * FROM performance_schema.global_variables WHERE VARIABLE_NAME = 'binlog_encryption'; -
若要關閉 binlog_encryption,請執行以下命令:
mysql> SET GLOBAL binlog_encryption = OFF;-或-
在 binlog_encryption 關閉的情況下啟動 AWS DMS 任務,接著請執行以下命令以開啟 binlog_encryption:mysql> SET GLOBAL binlog_encryption = ON;
相關資訊
- 語言
- 中文 (繁體)

相關內容
- 已提問 2 年前
