Cloud SQL Instance Management
Intermediate15 min
Create and manage Cloud SQL instances for PostgreSQL, MySQL, or SQL Server with backups, replicas, and connection management.
Prerequisites
- -gcloud CLI installed
- -GCP project with billing enabled
- -Cloud SQL Admin API enabled
Steps
1
Enable the Cloud SQL API
Activates the Cloud SQL Admin API.
$ gcloud services enable sqladmin.googleapis.com
2
Create a Cloud SQL instance
Creates a PostgreSQL 15 instance with auto-increasing storage.
$ gcloud sql instances create mydb --database-version POSTGRES_15 --tier db-f1-micro --region us-central1 --storage-size 10GB --storage-auto-increase
Instance creation takes 3-5 minutes. The db-f1-micro tier is for dev only.
3
Set the root password
Sets the password for the default postgres user.
$ gcloud sql users set-password postgres --instance mydb --password MY_SECURE_PASSWORD
4
Create a database
Creates a new database within the Cloud SQL instance.
$ gcloud sql databases create myappdb --instance mydb
5
Connect via Cloud SQL Proxy
Opens an interactive psql session through a secure tunnel without exposing the instance publicly.
$ gcloud sql connect mydb --user postgres --database myappdb
For application connections, use the Cloud SQL Auth Proxy sidecar or Cloud SQL Connector libraries.
Full Script
FAQ
Discussion
Loading comments...