本頁面說明如何設定 Cloud SQL 執行個體的公開 IP 連線。
簡介
您可以設定 Cloud SQL 執行個體擁有公開 IPv4 位址,並將授權位址加入執行個體,以接受來自特定 IP 位址或位址範圍的連線。
您無法將私人網路 (例如 10.x.x.x) 指定為授權網路。
SQL Server 執行個體的公開 IP 位址:
IPv6:執行個體不支援 IPv6。
IPv4:執行個體會自動指派靜態 IPv4 位址。只要執行個體處於關閉 (停用) 狀態,系統就會針對 IP 位址收取小額費用。
如需透過 IP 連線將管理用戶端連線至執行個體的相關說明,請參閱「使用 IP 位址連線 sqlcmd 用戶端 」。
如果將執行個體設為接受使用公開 IP 位址的連線,也請將執行個體設為使用 SSL,確保資料安全性。如需詳細資訊,請參閱為執行個體設定安全資料傳輸層 (SSL) 的說明。
如要使用未暴露於公開網際網路的 IP 位址來設定執行個體,請參閱設定私人 IP 連線 。
啟用公開 IP,並新增授權位址或位址範圍
為執行個體啟用公開 IP 時,Cloud SQL 會為執行個體設定公開靜態 IPv4 位址。啟用公開 IP 後,您必須設定資料庫連線的授權。詳情請參閱授權選項 。
如果您使用共用憑證授權單位 (CA) 或客戶自行管理的 CA 做為執行個體的 serverCaMode,則在為執行個體啟用公開 IP 時,必須重新啟動執行個體。如要進一步瞭解伺服器 CA 模式設定,請參閱「憑證授權單位 (CA) 」。
如要啟用公開 IP 並加入授權位址,請執行下列操作:
控制台
前往 Google Cloud 控制台的「Cloud SQL Instances」(Cloud SQL 執行個體) 頁面。
前往「Cloud SQL Instances」(Cloud SQL 執行個體) 頁面
點選執行個體名稱,開啟執行個體的「總覽」 頁面。
在 SQL 導覽選單中,選取「連線」 。
按一下 [網路] 分頁標籤。
選取 [公開 IP] 核取方塊。
按一下 [新增網路] 。
您也可以在「Name」(名稱) 欄位中輸入這個網路的名稱。
在「Network」(網路) 欄位中,輸入要允許連線的 IP 位址或位址範圍。使用 CIDR 標記法 。
按一下「完成」 。
按一下「儲存」 。
gcloud
如果您尚未將 IPv4 位址加入執行個體,請執行下列操作:
gcloud sql instances patch INSTANCE_NAME \
--assign-ip
透過描述執行個體來顯示所有現有的授權位址:
gcloud sql instances describe INSTANCE_NAME
在 [ipConfiguration] 下尋找 [authorizedNetwork] 項目,並記下您要保留的任何授權位址。
更新已授權網路清單,加入所有要納入的位址。
gcloud sql instances patch INSTANCE_NAME \
--authorized-networks= IP_ADDR1 ,IP_ADDR2 ...
使用 CIDR 標記法 。
確認變更:
gcloud sql instances describe INSTANCE_NAME
移除授權位址後,該位址的現有連線不會 中斷。如要中斷現有連線,請重新啟動執行個體。
REST v1
說明執行個體,顯示所有現有的授權位址:
使用任何要求資料之前,請先修改下列項目的值:
project-id :專案 ID
instance-id :執行個體 ID
machine-type 執行個體機型
zone :執行個體可用區
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings
請展開以下其中一個選項,以傳送要求:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"settings":
{
"authorizedGaeApplications": [],
"tier": "machine-type ",
"kind": "sql#settings",
"availabilityType": "REGIONAL",
"pricingPlan": "PER_USE",
"replicationType": "SYNCHRONOUS",
"activationPolicy": "ALWAYS",
"ipConfiguration":
{
"privateNetwork": "projects/project-id /global/networks/default",
"authorizedNetworks": [],
"ipv4Enabled": true
},
"locationPreference":
{
"zone": "zone ",
"kind": "sql#locationPreference"
},
"dataDiskType": "PD_SSD",
"maintenanceWindow":
{
"kind": "sql#maintenanceWindow",
"hour": 0,
"day": 0
},
"backupConfiguration":
{
"startTime": "03:00",
"kind": "sql#backupConfiguration",
"enabled": true,
"binaryLogEnabled": true
},
"settingsVersion": "54",
"storageAutoResizeLimit": "0",
"storageAutoResize": true,
"dataDiskSizeGb": "10"
}
}
更新執行個體,包括您要在執行個體上設定的「所有」 位址:
使用任何要求資料之前,請先修改下列項目的值:
project-id :專案 ID
instance-id :執行個體 ID
network_range_1 授權的 IP 位址或範圍
network_range_2 另一個授權 IP 位址或範圍
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id
JSON 要求主體:
{
"settings":
{
"ipConfiguration":
{
"authorizedNetworks":
[{"value": "network_range_1 "}, {"value": "network_range_2 "}]
}
}
}
請展開以下其中一個選項,以傳送要求:
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://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id "
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://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id " | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "UPDATE",
"name": "operation-id ",
"targetId": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id /operations/operation-id ",
"targetProject": "project-id "
}
使用 CIDR 標記法 。
確認變更:
使用任何要求資料之前,請先修改下列項目的值:
project-id :專案 ID
instance-id :執行個體 ID
ip-address1 :第一個 IP 位址的 CIDR 形式
ip-address-name1 :第一個 IP 位址的名稱
ip-address2 :第二個 IP 位址的 CIDR 形式
ip-address-name2 :第二個 IP 位址的名稱
machine-type 執行個體機型
zone :執行個體可用區
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings
請展開以下其中一個選項,以傳送要求:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"settings":
{
"authorizedGaeApplications": [],
"tier": "machine-type 4",
"kind": "sql#settings",
"availabilityType": "REGIONAL",
"pricingPlan": "PER_USE",
"replicationType": "SYNCHRONOUS",
"activationPolicy": "ALWAYS",
"ipConfiguration":
{
"privateNetwork": "projects/project-id /global/networks/default",
"authorizedNetworks":
[
{
"value": "ip-address1 ",
"name": "ip-address-name1 ",
"kind": "sql#aclEntry"
},
{
"value": "ip-address2 ",
"name": "ip-address-name2 ",
"kind": "sql#aclEntry"
}
],
"ipv4Enabled": true
},
"locationPreference":
{
"zone": "zone ",
"kind": "sql#locationPreference"
},
"dataDiskType": "PD_SSD",
"maintenanceWindow":
{
"kind": "sql#maintenanceWindow",
"hour": 0,
"day": 0
},
"backupConfiguration":
{
"startTime": "03:00",
"kind": "sql#backupConfiguration",
"enabled": true,
"binaryLogEnabled": true
},
"settingsVersion": "54",
"storageAutoResizeLimit": "0",
"storageAutoResize": true,
"dataDiskSizeGb": "10"
}
}
移除授權位址後,該位址的現有連線不會 中斷。如要中斷現有連線,請重新啟動執行個體。
如要啟用公開 IP 並新增授權位址或位址範圍,請使用 Terraform 資源 。
套用變更
如要在 Google Cloud 專案中套用 Terraform 設定,請完成下列各節的步驟。
準備 Cloud Shell
啟動 Cloud Shell 。
設定要套用 Terraform 設定的預設 Google Cloud 專案。
這項指令在每個專案中只需執行一次,且可在任何目錄中執行。
export GOOGLE_CLOUD_PROJECT=PROJECT_ID
如果您在 Terraform 設定檔中設定明確的值,環境變數就會遭到覆寫。
準備目錄
每個 Terraform 設定檔都必須有自己的目錄 (也稱為「根模組」 )。
在 Cloud Shell 中建立目錄,並在該目錄中建立新檔案。檔案名稱必須有 .tf 副檔名,例如 main.tf。在本教學課程中,這個檔案稱為 main.tf。
mkdir DIRECTORY && cd DIRECTORY && touch main.tf
如果您正在按照教學課程操作,可以複製每個章節或步驟中的程式碼範例。
將程式碼範例複製到新建立的 main.tf。
您也可以從 GitHub 複製程式碼。如果 Terraform 程式碼片段是端對端解決方案的一部分,建議您採用這種做法。
請查看並修改範例參數,以便套用至您的環境。
儲存變更。
初始化 Terraform。每個目錄只需執行一次這項操作。
terraform init
如要使用最新版 Google 供應商,請視需要加入 -upgrade 選項:
terraform init -upgrade
套用變更
查看設定,確認 Terraform 要建立或更新的資源符合預期:
terraform plan
視需要修正設定。
執行下列指令,並在提示中輸入 yes,套用 Terraform 設定:
terraform apply
等待 Terraform 顯示「Apply complete!」訊息。
開啟 Google Cloud 專案 即可查看結果。在 Google Cloud 控制台的 UI 中前往資源,確認 Terraform 已建立或更新資源。
注意: Terraform 範例通常會假設 Google Cloud 專案已啟用必要的 API。
刪除變更
如要刪除變更,請按照下列步驟操作:
如要停用防刪除功能,請在 Terraform 設定檔中將 deletion_protection 引數設為 false。
deletion_protection = "false"
執行下列指令,並在提示中輸入 yes,套用更新後的 Terraform 設定:
terraform apply
執行下列指令,並在提示中輸入 yes,移除先前使用 Terraform 設定套用的資源:
terraform destroy
REST v1beta4
說明執行個體,顯示所有現有的授權位址:
使用任何要求資料之前,請先修改下列項目的值:
project-id :專案 ID
instance-id :執行個體 ID
machine-type 執行個體機型
zone :執行個體可用區
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings
請展開以下其中一個選項,以傳送要求:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"settings":
{
"authorizedGaeApplications": [],
"tier": "machine-type ",
"kind": "sql#settings",
"availabilityType": "REGIONAL",
"pricingPlan": "PER_USE",
"replicationType": "SYNCHRONOUS",
"activationPolicy": "ALWAYS",
"ipConfiguration":
{
"privateNetwork": "projects/project-id /global/networks/default",
"authorizedNetworks": [],
"ipv4Enabled": true
},
"locationPreference":
{
"zone": "zone ",
"kind": "sql#locationPreference"
},
"dataDiskType": "PD_SSD",
"maintenanceWindow":
{
"kind": "sql#maintenanceWindow",
"hour": 0,
"day": 0
},
"backupConfiguration":
{
"startTime": "03:00",
"kind": "sql#backupConfiguration",
"enabled": true,
"binaryLogEnabled": true
},
"settingsVersion": "54",
"storageAutoResizeLimit": "0",
"storageAutoResize": true,
"dataDiskSizeGb": "10"
}
}
更新執行個體,包括您要在執行個體上設定的「所有」 位址:
使用任何要求資料之前,請先修改下列項目的值:
project-id :專案 ID
instance-id :執行個體 ID
network_range_1 授權的 IP 位址或範圍
network_range_2 另一個授權 IP 位址或範圍
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id
JSON 要求主體:
{
"settings":
{
"ipConfiguration":
{
"authorizedNetworks":
[{"value": "network_range_1 "}, {"value": "network_range_2 "}]
}
}
}
請展開以下其中一個選項,以傳送要求:
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://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id "
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://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id " | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "UPDATE",
"name": "operation-id ",
"targetId": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /operations/operation-id ",
"targetProject": "project-id "
}
使用 CIDR 標記法 。
確認變更:
使用任何要求資料之前,請先修改下列項目的值:
project-id :專案 ID
instance-id :執行個體 ID
ip-address1 :第一個 IP 位址的 CIDR 形式
ip-address-name1 :第一個 IP 位址的名稱
ip-address2 :第二個 IP 位址的 CIDR 形式
ip-address-name2 :第二個 IP 位址的名稱
machine-type 執行個體機型
zone :執行個體可用區
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings
請展開以下其中一個選項,以傳送要求:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"settings":
{
"authorizedGaeApplications": [],
"tier": "machine-type 4",
"kind": "sql#settings",
"availabilityType": "REGIONAL",
"pricingPlan": "PER_USE",
"replicationType": "SYNCHRONOUS",
"activationPolicy": "ALWAYS",
"ipConfiguration":
{
"privateNetwork": "projects/project-id /global/networks/default",
"authorizedNetworks":
[
{
"value": "ip-address1 ",
"name": "ip-address-name1 ",
"kind": "sql#aclEntry"
},
{
"value": "ip-address2 ",
"name": "ip-address-name2 ",
"kind": "sql#aclEntry"
}
],
"ipv4Enabled": true
},
"locationPreference":
{
"zone": "zone ",
"kind": "sql#locationPreference"
},
"dataDiskType": "PD_SSD",
"maintenanceWindow":
{
"kind": "sql#maintenanceWindow",
"hour": 0,
"day": 0
},
"backupConfiguration":
{
"startTime": "03:00",
"kind": "sql#backupConfiguration",
"enabled": true,
"binaryLogEnabled": true
},
"settingsVersion": "54",
"storageAutoResizeLimit": "0",
"storageAutoResize": true,
"dataDiskSizeGb": "10"
}
}
移除授權位址後,該位址的現有連線不會 中斷。如要中斷現有連線,請重新啟動執行個體。
移除授權位址或位址範圍
移除授權的位址:
gcloud
透過描述執行個體來顯示所有現有的授權位址:
gcloud sql instances describe INSTANCE_NAME
在 [ipConfiguration] 下尋找 [authorizedNetwork] 項目,並記下您要保留的任何授權位址。
更新授權網路清單,移除要刪除的位址。
gcloud sql instances patch INSTANCE_NAME \
--authorized-networks= IP_ADDR1 ,IP_ADDR2 ...
確認變更:
gcloud sql instances describe INSTANCE_NAME
REST v1
說明執行個體,顯示所有現有的授權位址:
使用任何要求資料之前,請先修改下列項目的值:
project-id :專案 ID
instance-id :執行個體 ID
ip-address1 :第一個 IP 位址的 CIDR 形式
ip-address-name1 :第一個 IP 位址的名稱
ip-address2 :第二個 IP 位址的 CIDR 形式
ip-address-name2 :第二個 IP 位址的名稱
machine-type 執行個體機型
zone :執行個體可用區
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings
請展開以下其中一個選項,以傳送要求:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"settings":
{
"authorizedGaeApplications": [],
"tier": "machine-type 4",
"kind": "sql#settings",
"availabilityType": "REGIONAL",
"pricingPlan": "PER_USE",
"replicationType": "SYNCHRONOUS",
"activationPolicy": "ALWAYS",
"ipConfiguration":
{
"privateNetwork": "projects/project-id /global/networks/default",
"authorizedNetworks":
[
{
"value": "ip-address1 ",
"name": "ip-address-name1 ",
"kind": "sql#aclEntry"
},
{
"value": "ip-address2 ",
"name": "ip-address-name2 ",
"kind": "sql#aclEntry"
}
],
"ipv4Enabled": true
},
"locationPreference":
{
"zone": "zone ",
"kind": "sql#locationPreference"
},
"dataDiskType": "PD_SSD",
"maintenanceWindow":
{
"kind": "sql#maintenanceWindow",
"hour": 0,
"day": 0
},
"backupConfiguration":
{
"startTime": "03:00",
"kind": "sql#backupConfiguration",
"enabled": true,
"binaryLogEnabled": true
},
"settingsVersion": "54",
"storageAutoResizeLimit": "0",
"storageAutoResize": true,
"dataDiskSizeGb": "10"
}
}
更新執行個體,加入要保留的所有位址,並捨棄要移除的位址:
使用任何要求資料之前,請先修改下列項目的值:
project-id :專案 ID
instance-id :執行個體 ID
network_range_1 要移除的授權 IP 位址或網路範圍
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id
JSON 要求主體:
{
"settings":
{
"ipConfiguration":
{
"authorizedNetworks":
[{"value": "network_range_1 "}]
}
}
}
請展開以下其中一個選項,以傳送要求:
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://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id "
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://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id " | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "UPDATE",
"name": "operation-id ",
"targetId": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id /operations/operation-id ",
"targetProject": "project-id "
}
確認變更:
使用任何要求資料之前,請先修改下列項目的值:
project-id :專案 ID
instance-id :執行個體 ID
ip-address :IP 位址的 CIDR 格式
ip-address-name :IP 位址的名稱
machine-type 執行個體機型
zone :執行個體可用區
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings
請展開以下其中一個選項,以傳送要求:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"settings":
{
"authorizedGaeApplications": [],
"tier": "machine-type ",
"kind": "sql#settings",
"availabilityType": "REGIONAL",
"pricingPlan": "PER_USE",
"replicationType": "SYNCHRONOUS",
"activationPolicy": "ALWAYS",
"ipConfiguration":
{
"privateNetwork": "projects/project-id /global/networks/default",
"authorizedNetworks":
[
{
"value": "ip-address ",
"name": "ip-address-name ",
"kind": "sql#aclEntry"
}
],
"ipv4Enabled": true
},
"locationPreference":
{
"zone": "zone ",
"kind": "sql#locationPreference"
},
"dataDiskType": "PD_SSD",
"maintenanceWindow":
{
"kind": "sql#maintenanceWindow",
"hour": 0,
"day": 0
},
"backupConfiguration":
{
"startTime": "03:00",
"kind": "sql#backupConfiguration",
"enabled": true,
"binaryLogEnabled": true
},
"settingsVersion": "54",
"storageAutoResizeLimit": "0",
"storageAutoResize": true,
"dataDiskSizeGb": "10"
}
}
REST v1beta4
說明執行個體,顯示所有現有的授權位址:
使用任何要求資料之前,請先修改下列項目的值:
project-id :專案 ID
instance-id :執行個體 ID
ip-address1 :第一個 IP 位址的 CIDR 形式
ip-address-name1 :第一個 IP 位址的名稱
ip-address2 :第二個 IP 位址的 CIDR 形式
ip-address-name2 :第二個 IP 位址的名稱
machine-type 執行個體機型
zone :執行個體可用區
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings
請展開以下其中一個選項,以傳送要求:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"settings":
{
"authorizedGaeApplications": [],
"tier": "machine-type 4",
"kind": "sql#settings",
"availabilityType": "REGIONAL",
"pricingPlan": "PER_USE",
"replicationType": "SYNCHRONOUS",
"activationPolicy": "ALWAYS",
"ipConfiguration":
{
"privateNetwork": "projects/project-id /global/networks/default",
"authorizedNetworks":
[
{
"value": "ip-address1 ",
"name": "ip-address-name1 ",
"kind": "sql#aclEntry"
},
{
"value": "ip-address2 ",
"name": "ip-address-name2 ",
"kind": "sql#aclEntry"
}
],
"ipv4Enabled": true
},
"locationPreference":
{
"zone": "zone ",
"kind": "sql#locationPreference"
},
"dataDiskType": "PD_SSD",
"maintenanceWindow":
{
"kind": "sql#maintenanceWindow",
"hour": 0,
"day": 0
},
"backupConfiguration":
{
"startTime": "03:00",
"kind": "sql#backupConfiguration",
"enabled": true,
"binaryLogEnabled": true
},
"settingsVersion": "54",
"storageAutoResizeLimit": "0",
"storageAutoResize": true,
"dataDiskSizeGb": "10"
}
}
更新執行個體,加入要保留的所有位址,並捨棄要移除的位址:
使用任何要求資料之前,請先修改下列項目的值:
project-id :專案 ID
instance-id :執行個體 ID
network_range_1 要移除的授權 IP 位址或網路範圍
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id
JSON 要求主體:
{
"settings":
{
"ipConfiguration":
{
"authorizedNetworks":
[{"value": "network_range_1 "}]
}
}
}
請展開以下其中一個選項,以傳送要求:
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://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id "
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://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id " | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "UPDATE",
"name": "operation-id ",
"targetId": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /operations/operation-id ",
"targetProject": "project-id "
}
確認變更:
使用任何要求資料之前,請先修改下列項目的值:
project-id :專案 ID
instance-id :執行個體 ID
ip-address :IP 位址的 CIDR 格式
ip-address-name :IP 位址的名稱
machine-type 執行個體機型
zone :執行個體可用區
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings
請展開以下其中一個選項,以傳送要求:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"settings":
{
"authorizedGaeApplications": [],
"tier": "machine-type ",
"kind": "sql#settings",
"availabilityType": "REGIONAL",
"pricingPlan": "PER_USE",
"replicationType": "SYNCHRONOUS",
"activationPolicy": "ALWAYS",
"ipConfiguration":
{
"privateNetwork": "projects/project-id /global/networks/default",
"authorizedNetworks":
[
{
"value": "ip-address ",
"name": "ip-address-name ",
"kind": "sql#aclEntry"
}
],
"ipv4Enabled": true
},
"locationPreference":
{
"zone": "zone ",
"kind": "sql#locationPreference"
},
"dataDiskType": "PD_SSD",
"maintenanceWindow":
{
"kind": "sql#maintenanceWindow",
"hour": 0,
"day": 0
},
"backupConfiguration":
{
"startTime": "03:00",
"kind": "sql#backupConfiguration",
"enabled": true,
"binaryLogEnabled": true
},
"settingsVersion": "54",
"storageAutoResizeLimit": "0",
"storageAutoResize": true,
"dataDiskSizeGb": "10"
}
}
移除授權位址後,系統不會 中斷該位址的現有連線。如要中斷現有連線,請重新啟動執行個體。
設定執行個體拒絕所有公開 IP 連線
要設定執行個體以拒絕所有公開 IP 連線:
gcloud
清除授權的位址清單:
gcloud sql instances patch INSTANCE_NAME \
--clear-authorized-networks
確認變更:
gcloud sql instances describe INSTANCE_NAME
REST v1
說明執行個體,顯示所有現有的授權位址:
使用任何要求資料之前,請先修改下列項目的值:
project-id :專案 ID
instance-id :執行個體 ID
ip-address1 :第一個 IP 位址的 CIDR 形式
ip-address-name1 :第一個 IP 位址的名稱
ip-address2 :第二個 IP 位址的 CIDR 形式
ip-address-name2 :第二個 IP 位址的名稱
machine-type 執行個體機型
zone :執行個體可用區
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings
請展開以下其中一個選項,以傳送要求:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"settings":
{
"authorizedGaeApplications": [],
"tier": "machine-type 4",
"kind": "sql#settings",
"availabilityType": "REGIONAL",
"pricingPlan": "PER_USE",
"replicationType": "SYNCHRONOUS",
"activationPolicy": "ALWAYS",
"ipConfiguration":
{
"privateNetwork": "projects/project-id /global/networks/default",
"authorizedNetworks":
[
{
"value": "ip-address1 ",
"name": "ip-address-name1 ",
"kind": "sql#aclEntry"
},
{
"value": "ip-address2 ",
"name": "ip-address-name2 ",
"kind": "sql#aclEntry"
}
],
"ipv4Enabled": true
},
"locationPreference":
{
"zone": "zone ",
"kind": "sql#locationPreference"
},
"dataDiskType": "PD_SSD",
"maintenanceWindow":
{
"kind": "sql#maintenanceWindow",
"hour": 0,
"day": 0
},
"backupConfiguration":
{
"startTime": "03:00",
"kind": "sql#backupConfiguration",
"enabled": true,
"binaryLogEnabled": true
},
"settingsVersion": "54",
"storageAutoResizeLimit": "0",
"storageAutoResize": true,
"dataDiskSizeGb": "10"
}
}
使用空白位址清單更新執行個體:
使用任何要求資料之前,請先修改下列項目的值:
project-id :專案 ID
instance-id :執行個體 ID
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id
JSON 要求主體:
{
"settings":
{
"ipConfiguration":
{
"authorizedNetworks": []
}
}
}
請展開以下其中一個選項,以傳送要求:
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://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id "
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://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id " | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "UPDATE",
"name": "operation-id ",
"targetId": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id /operations/operation-id ",
"targetProject": "project-id "
}
確認變更:
使用任何要求資料之前,請先修改下列項目的值:
project-id :專案 ID
instance-id :執行個體 ID
machine-type 執行個體機型
zone :執行個體可用區
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings
請展開以下其中一個選項,以傳送要求:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"settings":
{
"authorizedGaeApplications": [],
"tier": "machine-type ",
"kind": "sql#settings",
"availabilityType": "REGIONAL",
"pricingPlan": "PER_USE",
"replicationType": "SYNCHRONOUS",
"activationPolicy": "ALWAYS",
"ipConfiguration":
{
"privateNetwork": "projects/project-id /global/networks/default",
"authorizedNetworks": [],
"ipv4Enabled": true
},
"locationPreference":
{
"zone": "zone ",
"kind": "sql#locationPreference"
},
"dataDiskType": "PD_SSD",
"maintenanceWindow":
{
"kind": "sql#maintenanceWindow",
"hour": 0,
"day": 0
},
"backupConfiguration":
{
"startTime": "03:00",
"kind": "sql#backupConfiguration",
"enabled": true,
"binaryLogEnabled": true
},
"settingsVersion": "54",
"storageAutoResizeLimit": "0",
"storageAutoResize": true,
"dataDiskSizeGb": "10"
}
}
REST v1beta4
說明執行個體,顯示所有現有的授權位址:
使用任何要求資料之前,請先修改下列項目的值:
project-id :專案 ID
instance-id :執行個體 ID
ip-address1 :第一個 IP 位址的 CIDR 形式
ip-address-name1 :第一個 IP 位址的名稱
ip-address2 :第二個 IP 位址的 CIDR 形式
ip-address-name2 :第二個 IP 位址的名稱
machine-type 執行個體機型
zone :執行個體可用區
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings
請展開以下其中一個選項,以傳送要求:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"settings":
{
"authorizedGaeApplications": [],
"tier": "machine-type 4",
"kind": "sql#settings",
"availabilityType": "REGIONAL",
"pricingPlan": "PER_USE",
"replicationType": "SYNCHRONOUS",
"activationPolicy": "ALWAYS",
"ipConfiguration":
{
"privateNetwork": "projects/project-id /global/networks/default",
"authorizedNetworks":
[
{
"value": "ip-address1 ",
"name": "ip-address-name1 ",
"kind": "sql#aclEntry"
},
{
"value": "ip-address2 ",
"name": "ip-address-name2 ",
"kind": "sql#aclEntry"
}
],
"ipv4Enabled": true
},
"locationPreference":
{
"zone": "zone ",
"kind": "sql#locationPreference"
},
"dataDiskType": "PD_SSD",
"maintenanceWindow":
{
"kind": "sql#maintenanceWindow",
"hour": 0,
"day": 0
},
"backupConfiguration":
{
"startTime": "03:00",
"kind": "sql#backupConfiguration",
"enabled": true,
"binaryLogEnabled": true
},
"settingsVersion": "54",
"storageAutoResizeLimit": "0",
"storageAutoResize": true,
"dataDiskSizeGb": "10"
}
}
使用空白位址清單更新執行個體:
使用任何要求資料之前,請先修改下列項目的值:
project-id :專案 ID
instance-id :執行個體 ID
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id
JSON 要求主體:
{
"settings":
{
"ipConfiguration":
{
"authorizedNetworks": []
}
}
}
請展開以下其中一個選項,以傳送要求:
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://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id "
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://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id " | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "UPDATE",
"name": "operation-id ",
"targetId": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /operations/operation-id ",
"targetProject": "project-id "
}
確認變更:
使用任何要求資料之前,請先修改下列項目的值:
project-id :專案 ID
instance-id :執行個體 ID
machine-type 執行個體機型
zone :執行個體可用區
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings
請展開以下其中一個選項,以傳送要求:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"settings":
{
"authorizedGaeApplications": [],
"tier": "machine-type ",
"kind": "sql#settings",
"availabilityType": "REGIONAL",
"pricingPlan": "PER_USE",
"replicationType": "SYNCHRONOUS",
"activationPolicy": "ALWAYS",
"ipConfiguration":
{
"privateNetwork": "projects/project-id /global/networks/default",
"authorizedNetworks": [],
"ipv4Enabled": true
},
"locationPreference":
{
"zone": "zone ",
"kind": "sql#locationPreference"
},
"dataDiskType": "PD_SSD",
"maintenanceWindow":
{
"kind": "sql#maintenanceWindow",
"hour": 0,
"day": 0
},
"backupConfiguration":
{
"startTime": "03:00",
"kind": "sql#backupConfiguration",
"enabled": true,
"binaryLogEnabled": true
},
"settingsVersion": "54",
"storageAutoResizeLimit": "0",
"storageAutoResize": true,
"dataDiskSizeGb": "10"
}
}
移除授權位址後,系統不會 中斷該位址的現有連線。如要中斷現有連線,請重新啟動執行個體。
停用公開 IP
您可以停用公開 IP,但前提是執行個體也設為使用私人 IP。如要啟用私人 IP,請參閱「將現有執行個體設為使用私人 IP 」。
如果您使用共用憑證授權單位 (CA) 或客戶自行管理的 CA 做為執行個體的 serverCaMode,則在停用執行個體的公開 IP 時,必須重新啟動執行個體。如要進一步瞭解伺服器 CA 模式設定,請參閱「憑證授權單位 (CA) 」。
注意: 停用執行個體的公開 IP 時,系統會釋出其 IPv4 位址。如果日後重新啟用這個執行個體的公開 IP,系統會指派不同的 IPv4 位址,您也必須修改所有使用公開 IP 位址連線至這個執行個體的應用程式。
要停用公開 IP:
gcloud
更新執行個體:
gcloud sql instances patch INSTANCE_NAME \
--no-assign-ip
確認變更:
gcloud sql instances describe INSTANCE_NAME
REST v1
說明執行個體,顯示所有現有的授權位址:
使用任何要求資料之前,請先修改下列項目的值:
project-id :專案 ID
instance-id :執行個體 ID
ip-address1 :第一個 IP 位址的 CIDR 形式
ip-address-name1 :第一個 IP 位址的名稱
ip-address2 :第二個 IP 位址的 CIDR 形式
ip-address-name2 :第二個 IP 位址的名稱
machine-type 執行個體機型
zone :執行個體可用區
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings
請展開以下其中一個選項,以傳送要求:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"settings":
{
"authorizedGaeApplications": [],
"tier": "machine-type 4",
"kind": "sql#settings",
"availabilityType": "REGIONAL",
"pricingPlan": "PER_USE",
"replicationType": "SYNCHRONOUS",
"activationPolicy": "ALWAYS",
"ipConfiguration":
{
"privateNetwork": "projects/project-id /global/networks/default",
"authorizedNetworks":
[
{
"value": "ip-address1 ",
"name": "ip-address-name1 ",
"kind": "sql#aclEntry"
},
{
"value": "ip-address2 ",
"name": "ip-address-name2 ",
"kind": "sql#aclEntry"
}
],
"ipv4Enabled": true
},
"locationPreference":
{
"zone": "zone ",
"kind": "sql#locationPreference"
},
"dataDiskType": "PD_SSD",
"maintenanceWindow":
{
"kind": "sql#maintenanceWindow",
"hour": 0,
"day": 0
},
"backupConfiguration":
{
"startTime": "03:00",
"kind": "sql#backupConfiguration",
"enabled": true,
"binaryLogEnabled": true
},
"settingsVersion": "54",
"storageAutoResizeLimit": "0",
"storageAutoResize": true,
"dataDiskSizeGb": "10"
}
}
更新執行個體:
使用任何要求資料之前,請先修改下列項目的值:
PROJECT_ID: 專案 ID
INSTANCE_ID: 執行個體 ID
VPC_NETWORK_NAME: 指定要用於這個執行個體的虛擬私有雲 (VPC) 網路名稱。網路必須已設定私人服務存取權。
RANGE_NAME: 選填 。如果指定,則會設定分配 IP 範圍的範圍名稱。範圍名稱必須符合 RFC-1035 ,且長度介於 1 至 63 個字元。
AUTHORIZED_NETWORKS: 如果是公開 IP 連線,請指定可連至執行個體的授權網路連線。
如果執行個體使用公開 IP 位址,請將 ipv4Enabled 參數的值設為 true;如果執行個體使用私人 IP 位址,請將該參數的值設為 false。
您可以使用 sqlNetworkArchitecture 欄位,強制執行個體在建立時使用新的網路架構,即使專案尚未完全升級也沒問題。如要進一步瞭解新版網路架構及其影響,請參閱「將執行個體升級至新版網路架構 」和「分配 IP 位址範圍 」。
HTTP 方法和網址:
POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances
JSON 要求主體:
{
"name": "INSTANCE_ID ",
"region": "region",
"databaseVersion": "database-version",
"settings": {
"tier": "machine-type",
"ipConfiguration": {
"ipv4Enabled": false,
"privateNetwork": "projects/PROJECT_ID /global/networks/VPC_NETWORK_NAME ",
"allocatedIpRange": "RANGE_NAME "
"authorizedNetworks": [AUTHORIZED_NETWORKS ],
}
},
"sqlNetworkArchitecture": "NEW_NETWORK_ARCHITECTURE"
}
請展開以下其中一個選項,以傳送要求:
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://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances"
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://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "CREATE",
"name": "OPERATION_ID ",
"targetId": "INSTANCE_ID ",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /operations/OPERATION_ID ",
"targetProject": "PROJECT_ID "
}
確認變更:
使用任何要求資料之前,請先修改下列項目的值:
project-id :專案 ID
instance-id :執行個體 ID
machine-type 執行個體機型
zone :執行個體可用區
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings
請展開以下其中一個選項,以傳送要求:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=settings" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"settings":
{
"authorizedGaeApplications": [],
"tier": "machine-type ",
"kind": "sql#settings",
"availabilityType": "REGIONAL",
"pricingPlan": "PER_USE",
"replicationType": "SYNCHRONOUS",
"activationPolicy": "ALWAYS",
"ipConfiguration":
{
"privateNetwork": "projects/project-id /global/networks/default",
"authorizedNetworks": [],
"ipv4Enabled": false
},
"locationPreference":
{
"zone": "zone ",
"kind": "sql#locationPreference"
},
"dataDiskType": "PD_SSD",
"maintenanceWindow":
{
"kind": "sql#maintenanceWindow",
"hour": 0,
"day": 0
},
"backupConfiguration":
{
"startTime": "03:00",
"kind": "sql#backupConfiguration",
"enabled": true,
"binaryLogEnabled": true
},
"settingsVersion": "54",
"storageAutoResizeLimit": "0",
"storageAutoResize": true,
"dataDiskSizeGb": "10"
}
}
REST v1beta4
說明執行個體,顯示所有現有的授權位址:
使用任何要求資料之前,請先修改下列項目的值:
project-id :專案 ID
instance-id :執行個體 ID
ip-address1 :第一個 IP 位址的 CIDR 形式
ip-address-name1 :第一個 IP 位址的名稱
ip-address2 :第二個 IP 位址的 CIDR 形式
ip-address-name2 :第二個 IP 位址的名稱
machine-type 執行個體機型
zone :執行個體可用區
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings
請展開以下其中一個選項,以傳送要求:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"settings":
{
"authorizedGaeApplications": [],
"tier": "machine-type 4",
"kind": "sql#settings",
"availabilityType": "REGIONAL",
"pricingPlan": "PER_USE",
"replicationType": "SYNCHRONOUS",
"activationPolicy": "ALWAYS",
"ipConfiguration":
{
"privateNetwork": "projects/project-id /global/networks/default",
"authorizedNetworks":
[
{
"value": "ip-address1 ",
"name": "ip-address-name1 ",
"kind": "sql#aclEntry"
},
{
"value": "ip-address2 ",
"name": "ip-address-name2 ",
"kind": "sql#aclEntry"
}
],
"ipv4Enabled": true
},
"locationPreference":
{
"zone": "zone ",
"kind": "sql#locationPreference"
},
"dataDiskType": "PD_SSD",
"maintenanceWindow":
{
"kind": "sql#maintenanceWindow",
"hour": 0,
"day": 0
},
"backupConfiguration":
{
"startTime": "03:00",
"kind": "sql#backupConfiguration",
"enabled": true,
"binaryLogEnabled": true
},
"settingsVersion": "54",
"storageAutoResizeLimit": "0",
"storageAutoResize": true,
"dataDiskSizeGb": "10"
}
}
更新執行個體:
使用任何要求資料之前,請先修改下列項目的值:
PROJECT_ID: 專案 ID
INSTANCE_ID: 執行個體 ID
VPC_NETWORK_NAME: 指定要用於這個執行個體的虛擬私有雲 (VPC) 網路名稱。網路必須已設定私人服務存取權。
RANGE_NAME: 選填 。如果指定,則會設定分配 IP 範圍的範圍名稱。範圍名稱必須符合 RFC-1035 ,且長度介於 1 至 63 個字元。
AUTHORIZED_NETWORKS: 如果是公開 IP 連線,請指定可連至執行個體的授權網路連線。
如果執行個體使用公開 IP 位址,請將 ipv4Enabled 參數的值設為 true;如果執行個體使用私人 IP 位址,請將該參數的值設為 false。
您可以使用 sqlNetworkArchitecture 欄位,強制執行個體在建立時使用新的網路架構,即使專案尚未完全升級也沒問題。如要進一步瞭解新版網路架構及其影響,請參閱「將執行個體升級至新版網路架構 」和「分配 IP 位址範圍 」。
HTTP 方法和網址:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances
JSON 要求主體:
{
"name": "INSTANCE_ID ",
"region": "region",
"databaseVersion": "database-version",
"settings": {
"tier": "machine-type",
"ipConfiguration": {
"ipv4Enabled": false,
"privateNetwork": "projects/PROJECT_ID /global/networks/VPC_NETWORK_NAME ",
"allocatedIpRange": "RANGE_NAME "
"authorizedNetworks": [AUTHORIZED_NETWORKS ],
}
},
"sqlNetworkArchitecture": "NEW_NETWORK_ARCHITECTURE"
}
請展開以下其中一個選項,以傳送要求:
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://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances"
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://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "CREATE",
"name": "OPERATION_ID ",
"targetId": "INSTANCE_ID ",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /operations/OPERATION_ID ",
"targetProject": "PROJECT_ID "
}
確認變更:
使用任何要求資料之前,請先修改下列項目的值:
project-id :專案 ID
instance-id :執行個體 ID
machine-type 執行個體機型
zone :執行個體可用區
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings
請展開以下其中一個選項,以傳送要求:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=settings" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"settings":
{
"authorizedGaeApplications": [],
"tier": "machine-type ",
"kind": "sql#settings",
"availabilityType": "REGIONAL",
"pricingPlan": "PER_USE",
"replicationType": "SYNCHRONOUS",
"activationPolicy": "ALWAYS",
"ipConfiguration":
{
"privateNetwork": "projects/project-id /global/networks/default",
"authorizedNetworks": [],
"ipv4Enabled": false
},
"locationPreference":
{
"zone": "zone ",
"kind": "sql#locationPreference"
},
"dataDiskType": "PD_SSD",
"maintenanceWindow":
{
"kind": "sql#maintenanceWindow",
"hour": 0,
"day": 0
},
"backupConfiguration":
{
"startTime": "03:00",
"kind": "sql#backupConfiguration",
"enabled": true,
"binaryLogEnabled": true
},
"settingsVersion": "54",
"storageAutoResizeLimit": "0",
"storageAutoResize": true,
"dataDiskSizeGb": "10"
}
}
疑難排解
問題
疑難排解
Aborted connection。
可能的問題如下:
網路不穩定。
對 TCP 保持運作指令無回應 (用戶端或伺服器無回應,可能超載)
資料庫引擎連線生命週期已超過,伺服器會結束連線。
應用程式必須能容許網路故障,並遵循最佳做法 ,例如連線集區和重試。大多數連線集區程式都會盡可能擷取這些錯誤。否則,應用程式必須重試或正常失敗。
如要重試連線,建議採用下列方法:
指數輪詢 。每次重試時,以指數方式增加時間間隔。
此外,也請加入隨機輪詢。
結合這些方法有助於減少節流。
使用私人 IP 或虛擬私有雲網路對接時,連線逾時或發生一般連線錯誤。
連線嘗試失敗,出現一般逾時或連線錯誤,但沒有診斷詳細資料。
疑難排解步驟:
在來源用戶端和資料庫通訊埠 (MySQL 為 3306、PostgreSQL 為 5432、SQL Server 為 1433) 的 Cloud SQL 私人 IP 之間,執行 Network Intelligence Center Connectivity Tests 。這項測試會追蹤封包路徑,並判斷流量是否因防火牆規則、缺少路徑或對接設定錯誤而遭到捨棄。
確認虛擬私有雲網路對等互連連線狀態為「ACTIVE」。
確認虛擬私有雲網路中的防火牆規則允許資料庫通訊埠的輸入流量。
如果使用非 RFC 1918 位址範圍,請確認您已更新對接設定,匯出採用公開 IP 的子網路路徑。
如需更多詳細資料和 gcloud 診斷指令,請參閱「診斷虛擬私有雲網路和私人 IP 連線失敗 」。
錯誤訊息:Login failed for user ""
您可能會在 Microsoft Entra ID 驗證 期間遇到這項登入錯誤。如要解決這個問題,請確認這位 Microsoft Entra ID 使用者有 SQL Server 登入資訊。
私人 IP 執行個體的網路連線問題
設定整合時,您可能會遇到下列問題:
建立 Microsoft Entra ID 登入資訊的作業速度緩慢
無法建立 Microsoft Entra ID 登入
無法使用 Microsoft Entra ID 驗證連線至執行個體
如要進一步瞭解如何解決這些問題,請參閱「排解 Microsoft Entra ID 整合問題 」。
後續步驟