# Cloud SQL 雲端建置資料庫


# Google Cloud Platform Cloud SQL

Cloud SQL 就是 GCP 雲端計算平台上的資料庫相關服務,提供完善的資料庫操作 Google Cloud SDK 相關建置指令,也可以透過 Google Cloud Console UI 進行設置。


# 實際操作


# 透過 Google Cloud Console UI 設置


# Step.1 登入 GCP 帳戶後進到 Cloud SQL 的選項

# Step.2 選擇 Create Instance 建立執行個體

# Step.3 選擇資料庫引擎

# Step.4 填寫配置

資料庫名稱、密碼、資料庫版本、Region、以及其他額外選項

接者等待 Cloud SQL instance 顯示綠勾勾就建置完成了

# UI 設置真的非常簡單呢


# 透過 Google Cloud SDK 進行設置


# Step.1 Google Cloud SDK 設置

畢竟不在 GCP 內部操作,所以需要綁到你的專案裏頭

1
gcloud init

# Step.2 建置 Cloud SQL (這裡使用 Postgresql)

建立名子叫 postgre 的 postgresql 資料庫管理系統 14 版,地區 asia-east2
tier 是指計費方案

1
2
3
4
5
gcloud sql instances create postgre \
--activation-policy=ALWAYS \
--database-version=POSTGRES_14 \
--region=asia-east2 \
--tier=db-n1-standard-1

資料庫就建置完成了


# Step.3 建立資料庫 webalbum

需要給與參數 --instance 選定剛剛建置好的資料庫管理系統

1
gcloud sql databases create webalbum --instance postgre

測試 webalbum 是否被建立

1
gcloud sql databases list --instance webalbum

# Step.4 設置 Root 密碼

1
2
3
4
gcloud sql users set-password root \
--host=% \
--instance webalbum \
--password=PASSWORD

# 用 Google Cloud SDK 真的很快呢