提供意見
設定公開 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 後,您必須設定資料庫連線的授權。詳情請參閱「授權選項 」。
如果執行個體的 serverCaMode
使用共用憑證授權單位 (CA) 或客戶管理的 CA,啟用執行個體的公開 IP 時,執行個體必須重新啟動。如要進一步瞭解伺服器 CA 模式設定,請參閱「憑證授權單位 (CA) 授權 」。
如要啟用公開 IP 並加入授權位址,請執行下列操作:
控制台
前往 Google Cloud 控制台的「Cloud SQL Instances」 頁面。
前往 Cloud SQL 執行個體
如要開啟執行個體的「總覽」 頁面,請按一下執行個體名稱。
在 SQL 導覽選單中,選取「連線」 。
按一下 [網路] 分頁標籤。
選取 [公開 IP] 核取方塊。
按一下 [新增網路] 。
(選用) 在「Name」(名稱) 欄位中,輸入這個網路的名稱。
在「網路」 欄位中,輸入要允許連線的 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"
}
}
當您移除授權的位址時,來自該位址的現有連線「不會」 中斷。如要中斷現有連線,請重新啟動執行個體。
移除授權的位址或位址範圍
移除授權的位址:
控制台
前往 Google Cloud 控制台的「Cloud SQL Instances」 頁面。
前往 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": "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 連線:
控制台
前往 Google Cloud 控制台的「Cloud SQL Instances」 頁面。
前往 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": "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:
控制台
前往 Google Cloud 控制台的「Cloud SQL Instances」 頁面。
前往 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 連線,請指定可連線至執行個體的授權網路連線。
如果是 ipv4Enabled
參數,請將值設為 true
(如果您為執行個體使用公開 IP 位址),或設為 false
(如果執行個體有私人 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 ],
}
}
}
如要傳送要求,請展開以下其中一個選項:
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 連線,請指定可連線至執行個體的授權網路連線。
如果是 ipv4Enabled
參數,請將值設為 true
(如果您為執行個體使用公開 IP 位址),或設為 false
(如果執行個體有私人 IP 位址)。
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": "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/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-07-09 (世界標準時間)。
想進一步說明嗎?
[[["容易理解","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-07-09 (世界標準時間)。"],[],[]]