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: Cloud SQL editions (Enterprise
& Enterprise Plus), instance architecture, read pools, 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.
Disaster Recovery & Backups: Backup types,
Point-in-Time Recovery (PITR), replicas, read pools comparison, and Enterprise Plus Advanced DR.
If you need product information not found in these references, use the
Developer Knowledge MCP server search_documents tool.
Source: google/skills → skills/cloud/cloud-sql-basics/SKILL.md
1---
2name: cloud-sql-basics
3description: ">- This file generates or explains Cloud SQL resources. Use this file when the user asks to create a Cloud SQL instance or database for MySQL, PostgreSQL, or SQL Server. Cloud SQL manages third-party MySQL, PostgreSQL, and SQL Server instances as resources in Cloud SQL. For example, when Cloud SQL creates an open-source MySQL instance, the resulting resource is a Cloud SQL for MySQL instance that Google Cloud manages. Cloud SQL handles backups, high availability, and secure connectivity for relational database workloads."
4category: devops-and-infra
5source_repo: google/skills
6source_path: "skills/cloud/cloud-sql-basics/SKILL.md"
7source_url: https://github.com/google/skills/blob/HEAD/skills/cloud/cloud-sql-basics/SKILL.md
8metadata:
9 source: https://skillmd.com/skills/thedixitjain/cloud-sql-basics
10---
11
12
13# Cloud SQL Basics
14
15Cloud SQL is a fully managed relational database service for MySQL, PostgreSQL,
16and SQL Server. It automates time-consuming tasks like patches, updates,
17backups, and replicas, while providing high performance and availability for
18your applications.
19
20## Prerequisites
21
22Ensure you have the necessary IAM permissions to create and manage Cloud SQL
23instances. The **Cloud SQL Admin** (`roles/cloudsql.admin`) role provides full
24access to Cloud SQL resources.
25
26## Quick Start (PostgreSQL)
27
281. **Enable the API:**
29
30 ```bash
31 gcloud services enable sqladmin.googleapis.com --quiet
32 ```
33
342. **Create an Instance:**
35
36 ```bash
37 gcloud sql instances create INSTANCE_NAME \
38 --database-version=POSTGRES_18 \
39 --cpu=2 \
40 --memory=7680MiB \
41 --region=REGION \
42 --quiet
43 ```
44
453. **Set a password for the default user:**
46
47 Because this is a Cloud SQL for PostgreSQL instance, the default admin user
48 is `postgres`:
49
50 ```bash
51 gcloud sql users set-password postgres \
52 --instance=INSTANCE_NAME --password=PASSWORD \
53 --quiet
54 ```
55
564. **Create a database:**
57
58 ```bash
59 gcloud sql databases create DATABASE_NAME \
60 --instance=INSTANCE_NAME \
61 --quiet
62 ```
63
645. **Get the instance connection name:**
65
66 You need the instance connection name (which is formatted as
67 `PROJECT_ID:REGION:INSTANCE_NAME`) to connect using the Cloud SQL Auth
68 Proxy. Retrieve it with the following command:
69
70 ```bash
71 gcloud sql instances describe INSTANCE_NAME \
72 --format="value(connectionName)" \
73 --quiet
74 ```
75
766. **Connect to the instance:**
77
78 The Cloud SQL Auth Proxy must be running to be able to connect to the
79 instance. In a separate terminal, start the proxy using the connection name:
80
81 ```bash
82 ./cloud-sql-proxy INSTANCE_CONNECTION_NAME
83 ```
84
85 With the proxy running, connect using `psql` in another terminal:
86
87 ```bash
88 psql "host=127.0.0.1 port=5432 user=postgres dbname=DATABASE_NAME password=PASSWORD sslmode=disable"
89 ```
90
91## Reference Directory
92
93- [Core Concepts](references/core-concepts.md): Cloud SQL editions (Enterprise
94 & Enterprise Plus), instance architecture, read pools, high availability (HA),
95 and supported database engines.
96
97- [CLI Usage](references/cli-usage.md): Essential `gcloud sql` commands for
98 instance, database, and user management.
99
100- [Client Libraries & Connectors](references/client-library-usage.md):
101 Connecting to Cloud SQL using Python, Java, Node.js, and Go.
102
103- [MCP Usage](references/mcp-usage.md): Using the Cloud SQL remote MCP
104 server and Gemini CLI extension.
105
106- [Infrastructure as Code](references/iac-usage.md): Terraform
107 configuration for instances, databases, and users.
108
109- [IAM & Security](references/iam-security.md): Predefined roles, SSL/TLS
110 certificates, and Auth Proxy configuration.
111
112- [Disaster Recovery & Backups](references/dr-backups.md): Backup types,
113 Point-in-Time Recovery (PITR), replicas, read pools comparison, and Enterprise Plus Advanced DR.
114
115*If you need product information not found in these references, use the
116 Developer Knowledge MCP server `search_documents` tool.*
117
118---
119
120**Source:** [`google/skills`](https://github.com/google/skills) → `skills/cloud/cloud-sql-basics/SKILL.md`