總覽
本頁說明如何使用資料庫移轉服務 API 管理 MySQL 來源資料庫的連線設定檔。
您可以透過兩種方式使用資料庫移轉服務 API。您可以發出 REST API 呼叫,也可以使用 Google Cloud CLI (CLI)。
如要查看使用 gcloud
管理資料庫遷移服務連線設定檔的概略資訊,請按這裡。
為 MySQL 來源資料庫建立連線設定檔
以下是建立 MySQL 來源資料庫連線設定檔的要求。
使用任何要求資料之前,請先替換以下項目:
- project-id:專案 ID
- region:專案區域
- connection-profile-id:連線設定檔 ID
- connection-profile-display-name:連線設定檔顯示名稱
- host-ip-address:來源 IP 位址
- username:資料庫使用者名稱
- password:資料庫使用者密碼
- client-key:與用戶端憑證相關聯的未加密 PKCS#1 或 PKCS#8 PEM 編碼私密金鑰。如果使用這個欄位,則必須填寫
clientCertificate
欄位。 - client-certificate:備用資源在驗證來源資料庫伺服器時所用的憑證,採用 x509 PEM 編碼。如果使用這個欄位,則必須使用
clientKey
欄位。 - ca-certificate:必填。簽署來源資料庫伺服器憑證的 CA 憑證,採用 x509 PEM 編碼。備用資源會透過這項憑證確認所連結的主機是否正確。
HTTP 方法和網址:
POST https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles?connectionProfileId=connection-profile-id
JSON 要求主體:
{ "displayName": "connection-profile-display-name ", "mysql": { "host": "host-ip-address ", "port": 3306, "username": "username ", "password": "password ", "ssl": { "clientKey": "client-key ", "clientCertificate": "client-certificate ", "caCertificate": "ca-certificate " } } }
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles?connectionProfileId=connection-profile-id "
PowerShell (Windows)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles?connectionProfileId=connection-profile-id " | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
{ "name": "projects/project-id /locations/region /operations/operation-1591973161667-5a7e422cb0ba4-3004980d-2ae97165", "metadata": { "@type": "type.googleapis.com/google.cloud.clouddms.v1.OperationMetadata", "createTime": "2020-06-12T14:46:01.744267779Z", "target": "projects/project-id /locations/region /connectionProfiles/connection-profile-id ", "verb": "create", "requestedCancellation": false, "apiVersion": "v1" }, "done": false }
如要查看使用 gcloud
建立資料庫遷移服務連線設定檔的概略資訊,請按這裡。
如要進一步瞭解如何使用 gcloud
為 MySQL 來源資料庫建立連線設定檔,請按這裡。
建立完成後,您可以呼叫 connectionProfiles/get
方法,查看連線設定檔的相關資訊。
使用任何要求資料之前,請先替換以下項目:
- project-id:專案 ID
- region:專案區域
- connection-profile-id:連線設定檔 ID
HTTP 方法和網址:
GET https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id "
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id " | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
{ "name": "projects/project-id /locations/region /connectionProfiles/connection-profile-id ", "createTime": "2019-12-22T16:17:37.159786963Z", "updateTime": "2019-12-24T13:13:39.455857411Z", "state": "READY", "displayName": "connection-profile-display-name ", "mysql": { "host": "host-ip-address ", "port": 3306, "username": "username " } }
如要進一步瞭解如何使用 gcloud
擷取連結設定檔的相關資訊,請按這裡。
為 MySQL 適用的 Cloud SQL 來源資料庫建立連線設定檔
以下是建立 MySQL 適用的 Cloud SQL 來源資料庫連線設定檔的要求。這個範例會使用 MySQL 連線設定檔,因為它會連線至 MySQL 資料庫引擎,而非 Cloud SQL 管理層。
如要使用 Cloud SQL 建立來源和備用資源之間的配對關係,您必須提供 Cloud SQL 資料庫的執行個體 ID。您可以使用 Cloud SQL Admin API 的 databases/list
方法,找出執行個體 ID 值。
使用任何要求資料之前,請先替換以下項目:
- project-id:專案 ID
- region:專案區域
- connection-profile-id:連線設定檔 ID
- connection-profile-display-name:連線設定檔顯示名稱
- host-ip-address:來源 IP 位址
- username:資料庫使用者名稱
- password:資料庫使用者密碼
- cloud-sql-instance-id:Cloud SQL 執行個體 ID
HTTP 方法和網址:
POST https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles?connectionProfileId=connection-profile-id
JSON 要求主體:
{ "displayName": "connection-profile-display-name ", "mysql": { "host": "host-ip-address ", "port": 3306, "username": "username ", "password": "password ", "cloud_sql_id": "cloud-sql-instance-id " } }
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles?connectionProfileId=connection-profile-id "
PowerShell (Windows)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles?connectionProfileId=connection-profile-id " | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
{ "name": "projects/project-id /locations/region /operations/operation-1591973161667-5a7e422cb0ba4-3004980d-2ae97165", "metadata": { "@type": "type.googleapis.com/google.cloud.clouddms.v1.OperationMetadata", "createTime": "2020-06-12T14:46:01.744267779Z", "target": "projects/project-id /locations/region /connectionProfiles/connection-profile-id ", "verb": "create", "requestedCancellation": false, "apiVersion": "v1" }, "done": false }
如要查看使用 gcloud
建立資料庫遷移服務連線設定檔的概略資訊,請按這裡。
如要進一步瞭解如何使用 gcloud
為 MySQL 適用的 Cloud SQL 來源資料庫建立連線設定檔,請按這裡。
為 MySQL 適用的 Cloud SQL 目的地建立連線設定檔
以下是建立 MySQL 適用的 Cloud SQL 目的地連線設定檔的要求。資料庫移轉服務會使用這項要求中的資訊,建立新的 MySQL 適用 Cloud SQL 執行個體。
使用任何要求資料之前,請先替換以下項目:
- project-id:專案 ID
- region:專案區域
- connection-profile-id:連線設定檔 ID
- connection-profile-display-name:連線設定檔顯示名稱
- database-version:資料庫版本。例如 MYSQL_5_7。
- tier:機器類型。例如 db-custom-1-4096。
- data-disk-type:資料磁碟類型。例如 PD_SSD。
- data-disk-size-gb:資料磁碟大小 (以 GB 為單位)。例如 20。
- zone:專案區域中的區域
- cmek_key_name:選用:客戶管理的加密金鑰 (CMEK) 的完整路徑和名稱。例如「projects/project-id/locations/location/keyRings/ring/cryptoKeys/customer-managed-encryption-key」。
所有儲存在 Google Cloud 的靜態資料,都會透過強化版金鑰管理系統進行加密。這個系統與 Google 加密自家資料時使用的系統相同,這些金鑰管理系統提供嚴格的金鑰存取權控管和稽核機制,並使用 AES-256 加密標準加密靜態使用者資料。不需要設定、調整或管理。如果使用者對加密編譯資料的遵循規定或位置沒有特定要求, Google Cloud的預設靜態加密機制就是最佳選擇。
如果您需要進一步控管用於在 Google Cloud 專案中加密靜態資料的金鑰,Database Migration Service 可讓您使用在 Cloud Key Management Service (KMS) 中管理的加密金鑰來保護資料。這些加密金鑰稱為「客戶自行管理的加密金鑰」,簡稱「CMEK」。使用 CMEK 保護資料庫移轉服務中的資料時,您可以自行控管 CMEK。
cmek_key_name
參數與 CMEK 相關聯,資料庫移轉服務可使用 CMEK 將從來源遷移至目的地的資料加密。CMEK 由 customer-managed-encryption-key 預留位置表示。
ring 預留位置代表 CMEK 的金鑰環。金鑰環會將金鑰分組並存放在特定位置 Google Cloud ,讓您管理金鑰群組的存取權。金鑰環的名稱在 Google Cloud 專案中不必不重複,但在特定位置中必須不重複。如要進一步瞭解鑰匙圈,請參閱「Cloud KMS 資源」。
在建立連線設定檔的過程中,資料庫移轉服務會驗證 CMEK 是否存在,以及資料庫移轉服務是否具備使用金鑰的權限。
如果不符合上述任一條件,系統會傳回以下錯誤訊息:
CMEK_DOES_NOT_EXIST_OR_MISSING_PERMISSIONS
如要解決這個問題,請確認您提供的金鑰確實存在,且 Database Migration Service 服務帳戶具有該金鑰的 cloudkms.cryptoKeys.get
權限。
如果您偏好使用 Google Cloud的內部金鑰管理系統,而非 CMEK 來加密資料,請勿在 API 要求中加入 cmek_key_name
參數和值。
HTTP 方法和網址:
POST https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles?connectionProfileId=connection-profile-id
JSON 要求主體:
{ "displayName": "connection-profile-display-name ", "cloudsql": { "settings": { "databaseVersion": "database-version ", "tier": "machine-type ", "storageAutoResizeLimit": 0, "activationPolicy": "ALWAYS", "ipConfig": { "authorizedNetworks": [], "enableIpv4": true, "privateNetwork": null }, "autoStorageIncrease": false, "dataDiskType": "data-disk-type ", "dataDiskSizeGb": "data-disk-size ", "zone": "zone ", "sourceId": "projects/project-id /locations/region /connectionProfiles/connection-profile-id ", "cmek_key_name": "projects/project-id /locations/location /keyRings/ring /cryptoKeys/customer-managed-encryption-key " } } }
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles?connectionProfileId=connection-profile-id "
PowerShell (Windows)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles?connectionProfileId=connection-profile-id " | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
{ "name": "projects/project-id /locations/region /operations/operation-1591975557292-5a7e4b195623c-e350e3da-713dee7d", "metadata": { "@type": "type.googleapis.com/google.cloud.clouddms.v1.OperationMetadata", "createTime": "2020-06-12T15:25:57.430715421Z", "target": "projects/project-id /locations/region /connectionProfiles/connection-profile-id ", "verb": "create", "requestedCancellation": false, "apiVersion": "v1" }, "done": false }
如要查看使用 gcloud
建立資料庫遷移服務連線設定檔的概略資訊,請按這裡。
取得連線設定檔相關資訊
使用任何要求資料之前,請先替換以下項目:
- project-id:專案 ID
- region:專案區域
- connection-profile-id:連線設定檔 ID
HTTP 方法和網址:
GET https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id "
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id " | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
{ "name": "projects/project-id /locations/region /connectionProfiles/connection-profile-id ", "createTime": "2019-12-22T16:17:37.159786963Z", "updateTime": "2019-12-24T13:13:39.455857411Z", "state": "READY", "displayName": "connection-profile-display-name ", "mysql": { "host": "host-ip-address ", "port": 3306, "username": "username " } }
如要進一步瞭解如何使用 gcloud
擷取連結設定檔的相關資訊,請按這裡。
列出連線設定檔
以下是擷取所有連線設定檔資訊的要求。
使用任何要求資料之前,請先替換以下項目:
- project-id:專案 ID
- region:專案區域
orderBy:
使用這個篩選器,即可依字母順序擷取特定地區的所有連線設定檔清單。舉例來說,orderBy=name
篩選器會依名稱依序傳回所有連線設定檔。-
pageSize:
使用這個篩選器,指定資料庫遷移服務在頁面上擷取及顯示的連線設定檔上限。舉例來說,設定pageSize=10
後,資料庫遷移服務會針對一個網頁傳回最多 10 個連線設定檔。
如果連線設定檔超過 10 個,則會顯示在其他頁面。每個頁面的結尾都會顯示 nextPageToken
參數和不重複 ID。使用 ID 擷取下列頁面的連線設定檔清單。
HTTP 方法和網址:
GET https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles" | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
{ "connectionProfiles": [ { "name": "projects/project-id /locations/region /connectionProfiles/name-of-first-connection-profile ", "createTime": "2019-12-22T16:17:37.159786963Z", "updateTime": "2019-12-24T13:13:39.455857411Z", "state": "READY", "displayName": "display-name-of-first-connection-profile ", "mysql": { "host": "host-ip-address-of-first-connection-profile ", "port":port-number-of-first-connection-profile , "username": "username-of-first-connection-profile ", "password_set": "true" } } { "name": "projects/project-id /locations/region /connectionProfiles/name-of-second-connection-profile ", "createTime": "2020-11-21T19:22:25.153824963Z", "updateTime": "2020-11-11T11:15:14.451046111Z", "state": "READY", "displayName": "display-name-of-second-connection-profile ", "mysql": { "host": "host-ip-address-of-second-connection-profile ", "port":port-number-of-second-connection-profile , "username": "username-of-second-connection-profile ", "password_set": "true" } } ] }
如要進一步瞭解如何使用 gcloud
擷取所有連結設定檔的相關資訊,請按這裡。
更新連線設定檔
以下是要求更新現有連線設定檔的使用者名稱和密碼欄位。在要求中使用 updateMask
參數後,要求主體中只需包含這些欄位即可。
使用任何要求資料之前,請先替換以下項目:
- project-id:專案 ID
- region:專案區域
- connection-profile-id:連線設定檔 ID
- username:資料庫使用者名稱
- password:資料庫使用者密碼
HTTP 方法和網址:
PATCH https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id ?updateMask=mysql.username,mysql.password
JSON 要求主體:
{ "mysql" { "username": "username", "password": "password" } }
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id ?updateMask=mysql.username,mysql.password"
PowerShell (Windows)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id ?updateMask=mysql.username,mysql.password" | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
{ "name": "projects/project-id /locations/region /operations/operation-1591973161667-5a7e422cb0ba4-3004980d-2ae97165", "metadata": { "@type": "type.googleapis.com/google.cloud.clouddms.v1.OperationMetadata", "createTime": "2020-06-12T14:46:01.744267779Z", "target": "projects/project-id /locations/region /connectionProfiles/connection-profile-id ", "verb": "update", "requestedCancellation": false, "apiVersion": "v1" }, "done": false }
如要進一步瞭解如何使用 gcloud
更新連線設定檔,請按這裡。
刪除連線設定檔
使用任何要求資料之前,請先替換以下項目:
- project-id:專案 ID
- region:專案區域
- connection-profile-id:連線設定檔 ID
HTTP 方法和網址:
DELETE https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id "
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id " | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
{ "name": "projects/project-id /locations/region /operations/operation-1591973161667-5a7e422cb0ba4-3004980d-2ae97165", "metadata": { "@type": "type.googleapis.com/google.cloud.clouddms.v1.OperationMetadata", "createTime": "2020-06-12T14:46:01.744267779Z", "target": "projects/project-id /locations/region /connectionProfiles/connection-profile-id ", "verb": "delete", "requestedCancellation": false, "apiVersion": "v1" }, "done": false }
如要進一步瞭解如何使用 gcloud
刪除連線設定檔,請按這裡。
刪除連線設定檔和相關聯的 Cloud SQL 執行個體
以下是刪除目的地連線設定檔的請求,以及連帶刪除相關 Cloud SQL 執行個體的示例。
使用任何要求資料之前,請先替換以下項目:
- project-id:專案 ID
- region:專案區域
- connection-profile-id:連線設定檔 ID
HTTP 方法和網址:
DELETE https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id ?force=true
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id ?force=true"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id ?force=true" | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
{ "name": "projects/project-id /locations/region /operations/operation-1591973161667-5a7e422cb0ba4-3004980d-2ae97165", "metadata": { "@type": "type.googleapis.com/google.cloud.clouddms.v1.OperationMetadata", "createTime": "2020-06-12T14:46:01.744267779Z", "target": "projects/project-id /locations/region /connectionProfiles/connection-profile-id ", "verb": "create", "requestedCancellation": false, "apiVersion": "v1" }, "done": false }
如要進一步瞭解如何使用 gcloud
刪除連線設定檔和相關聯的 Cloud SQL 執行個體,請按這裡。