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