Cloud SQL Basics
Cloud SQL is a fully managed relational database service for MySQL, PostgreSQL,
and SQL Server. It automates time-consuming tasks like patches, updates,
backups, and replicas, while providing high performance and availability for
your applications.
Prerequisites
Ensure you have the necessary IAM permissions to create and manage Cloud SQL
instances. The Cloud SQL Admin (roles/cloudsql.admin) role provides full
access to Cloud SQL resources.
Quick Start (PostgreSQL)
Enable the API:
gcloud services enable sqladmin.googleapis.com --quiet
Create an Instance:
gcloud sql instances create INSTANCE_NAME \
--database-version=POSTGRES_18 \
--cpu=2 \
--memory=7680MiB \
--region=REGION \
--quiet
Set a password for the default user:
Because this is a Cloud SQL for PostgreSQL instance, the default admin user
is postgres:
gcloud sql users set-password postgres \
--instance=INSTANCE_NAME --password=PASSWORD \
--quiet
Create a database:
gcloud sql databases create DATABASE_NAME \
--instance=INSTANCE_NAME \
--quiet
Get the instance connection name:
You need the instance connection name (which is formatted as
PROJECT_ID:REGION:INSTANCE_NAME) to connect using the Cloud SQL Auth
Proxy. Retrieve it with the following command:
gcloud sql instances describe INSTANCE_NAME \
--format="value(connectionName)" \
--quiet
Connect to the instance:
The Cloud SQL Auth Proxy must be running to be able to connect to the
instance. In a separate terminal, start the proxy using the connection name:
./cloud-sql-proxy INSTANCE_CONNECTION_NAME
With the proxy running, connect using psql in another terminal:
psql "host=127.0.0.1 port=5432 user=postgres dbname=DATABASE_NAME password=PASSWORD sslmode=disable"
Reference Directory
Core Concepts: Instance architecture, high
availability (HA), and supported database engines.
CLI Usage: Essential gcloud sql commands for
instance, database, and user management.
Client Libraries & Connectors:
Connecting to Cloud SQL using Python, Java, Node.js, and Go.
MCP Usage: Using the Cloud SQL remote MCP
server and Gemini CLI extension.
Infrastructure as Code: Terraform
configuration for instances, databases, and users.
IAM & Security: Predefined roles, SSL/TLS
certificates, and Auth Proxy configuration.
If you need product information not found in these references, use the
Developer Knowledge MCP server search_documents tool.
1---2name: cloud-sql-basics3metadata:4 source: https://skillmd.com/skills/google/cloud-sql-basics5 category: Databases6description: >-7 This file generates or explains Cloud SQL resources. Use this file when the8 user asks to create a Cloud SQL instance or database for MySQL, PostgreSQL, or9 SQL Server.1011 Cloud SQL manages third-party MySQL, PostgreSQL, and SQL Server instances as12 resources in Cloud SQL. For example, when Cloud SQL creates an open-source13 MySQL instance, the resulting resource is a Cloud SQL for MySQL instance that14 Google Cloud manages.1516 Cloud SQL handles backups, high availability, and secure connectivity for17 relational database workloads.18---1920# Cloud SQL Basics2122Cloud SQL is a fully managed relational database service for MySQL, PostgreSQL,23and SQL Server. It automates time-consuming tasks like patches, updates,24backups, and replicas, while providing high performance and availability for25your applications.2627## Prerequisites2829Ensure you have the necessary IAM permissions to create and manage Cloud SQL30instances. The **Cloud SQL Admin** (`roles/cloudsql.admin`) role provides full31access to Cloud SQL resources.3233## Quick Start (PostgreSQL)34351. **Enable the API:**36 37 ```bash38 gcloud services enable sqladmin.googleapis.com --quiet39 ```40412. **Create an Instance:**42 43 ```bash44 gcloud sql instances create INSTANCE_NAME \45 --database-version=POSTGRES_18 \46 --cpu=2 \47 --memory=7680MiB \48 --region=REGION \49 --quiet50 ```51523. **Set a password for the default user:**5354 Because this is a Cloud SQL for PostgreSQL instance, the default admin user55 is `postgres`:56 57 ```bash58 gcloud sql users set-password postgres \59 --instance=INSTANCE_NAME --password=PASSWORD \60 --quiet61 ```62634. **Create a database:**64 65 ```bash66 gcloud sql databases create DATABASE_NAME \67 --instance=INSTANCE_NAME \68 --quiet69 ```70715. **Get the instance connection name:**7273 You need the instance connection name (which is formatted as74 `PROJECT_ID:REGION:INSTANCE_NAME`) to connect using the Cloud SQL Auth75 Proxy. Retrieve it with the following command:76 77 ```bash78 gcloud sql instances describe INSTANCE_NAME \79 --format="value(connectionName)" \80 --quiet81 ```82836. **Connect to the instance:**8485 The Cloud SQL Auth Proxy must be running to be able to connect to the86 instance. In a separate terminal, start the proxy using the connection name:87 88 ```bash89 ./cloud-sql-proxy INSTANCE_CONNECTION_NAME90 ```9192 With the proxy running, connect using `psql` in another terminal:93 94 ```bash95 psql "host=127.0.0.1 port=5432 user=postgres dbname=DATABASE_NAME password=PASSWORD sslmode=disable"96 ```9798## Reference Directory99100- [Core Concepts](references/core-concepts.md): Instance architecture, high101 availability (HA), and supported database engines.102103- [CLI Usage](references/cli-usage.md): Essential `gcloud sql` commands for104 instance, database, and user management.105106- [Client Libraries & Connectors](references/client-library-usage.md):107 Connecting to Cloud SQL using Python, Java, Node.js, and Go.108109- [MCP Usage](references/mcp-usage.md): Using the Cloud SQL remote MCP110 server and Gemini CLI extension.111112- [Infrastructure as Code](references/iac-usage.md): Terraform113 configuration for instances, databases, and users.114115- [IAM & Security](references/iam-security.md): Predefined roles, SSL/TLS116 certificates, and Auth Proxy configuration.117118*If you need product information not found in these references, use the119 Developer Knowledge MCP server `search_documents` tool.*