提供意見
設定公開 IP
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本頁面說明如何設定 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 執行個體」 頁面。
前往 Cloud SQL 執行個體
如要開啟執行個體的「總覽」 頁面,請按一下執行個體名稱。
在 SQL 導覽選單中,選取「連結」 。
按一下 [網路] 分頁標籤。
選取 [公開 IP] 核取方塊。
按一下 [新增網路] 。
您可以選擇在「名稱」欄位中輸入網路名稱。
在「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": "[email protected] ",
"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
如要移除先前透過 Terraform 設定套用的資源,請執行下列指令,並在提示中輸入 yes
:
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": "[email protected] ",
"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"
}
}
當您移除授權的位址時,來自該位址的現有連線「不會」 中斷。如果您要中斷現有連線,請重新啟動執行個體。
移除授權的位址或位址範圍
移除授權的位址:
控制台
前往 Google Cloud 控制台的「Cloud SQL 執行個體」 頁面。
前往 Cloud SQL 執行個體
如要開啟執行個體的「總覽」 頁面,請按一下執行個體名稱。
在 SQL 導覽選單中選取「Connections」 。
找出要刪除的位址,然後按一下相對應的刪除圖示 。
按一下 [Save] (儲存) 以更新執行個體。
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": "[email protected] ",
"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": "[email protected] ",
"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 連線:
控制台
前往 Google Cloud 控制台的「Cloud SQL 執行個體」 頁面。
前往 Cloud SQL 執行個體
如要開啟執行個體的「總覽」 頁面,請按一下執行個體名稱。
在 SQL 導覽選單中選取「Connections」 。
按一下所有已授權位址的刪除圖示 。
按一下 [Save] (儲存) 以更新執行個體。
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": "[email protected] ",
"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": "[email protected] ",
"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:
控制台
前往 Google Cloud 控制台的「Cloud SQL 執行個體」 頁面。
前往 Cloud SQL 執行個體
如要開啟執行個體的「總覽」 頁面,請按一下執行個體名稱。
在 SQL 導覽選單中選取「Connections」 。
取消勾選「Public IP」(公開 IP) 核取方塊。
按一下 [Save] (儲存) 以更新執行個體。
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
。
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 ],
}
}
}
如要傳送要求,請展開以下其中一個選項:
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": "[email protected] ",
"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
。
HTTP 方法和網址:
POST https://sqladmin.googleapis.com/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 ],
}
}
}
如要傳送要求,請展開以下其中一個選項:
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/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/v1beta4/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": "[email protected] ",
"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/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 保活指令沒有回應 (用戶端或伺服器沒有回應,可能已超載)
資料庫引擎連線逾時,因此伺服器會終止連線。
應用程式必須能容許網路失敗,並遵循最佳做法 ,例如連線集區和重試。大多數連線集區會盡可能擷取這些錯誤。否則,應用程式必須重新嘗試或優雅失敗。
針對連線重試,我們建議採用下列方法:
指數輪詢 。每次重試之間的時間間隔會以指數方式增加。
也新增隨機退避。
結合這些方法有助於減少頻寬限制。
後續步驟
提供意見
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權 ,程式碼範例則為阿帕契 2.0 授權 。詳情請參閱《Google Developers 網站政策 》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-05-16 (世界標準時間)。
想進一步說明嗎?
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-05-16 (世界標準時間)。"],[],[]]