$npx -y skills add google/skills --skill cloud-sql-basicsThis 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,
| 1 | # Cloud SQL Basics |
| 2 | |
| 3 | Cloud SQL is a fully managed relational database service for MySQL, PostgreSQL, |
| 4 | and SQL Server. It automates time-consuming tasks like patches, updates, |
| 5 | backups, and replicas, while providing high performance and availability for |
| 6 | your applications. |
| 7 | |
| 8 | ## Prerequisites |
| 9 | |
| 10 | Ensure you have the necessary IAM permissions to create and manage Cloud SQL |
| 11 | instances. The **Cloud SQL Admin** (`roles/cloudsql.admin`) role provides full |
| 12 | access to Cloud SQL resources. |
| 13 | |
| 14 | ## Quick Start (PostgreSQL) |
| 15 | |
| 16 | 1. **Enable the API:** |
| 17 | |
| 18 | ```bash |
| 19 | gcloud services enable sqladmin.googleapis.com --quiet |
| 20 | ``` |
| 21 | |
| 22 | 2. **Create an Instance:** |
| 23 | |
| 24 | ```bash |
| 25 | gcloud sql instances create INSTANCE_NAME \ |
| 26 | --database-version=POSTGRES_18 \ |
| 27 | --cpu=2 \ |
| 28 | --memory=7680MiB \ |
| 29 | --region=REGION \ |
| 30 | --quiet |
| 31 | ``` |
| 32 | |
| 33 | 3. **Set a password for the default user:** |
| 34 | |
| 35 | Because this is a Cloud SQL for PostgreSQL instance, the default admin user |
| 36 | is `postgres`: |
| 37 | |
| 38 | ```bash |
| 39 | gcloud sql users set-password postgres \ |
| 40 | --instance=INSTANCE_NAME --password=PASSWORD \ |
| 41 | --quiet |
| 42 | ``` |
| 43 | |
| 44 | 4. **Create a database:** |
| 45 | |
| 46 | ```bash |
| 47 | gcloud sql databases create DATABASE_NAME \ |
| 48 | --instance=INSTANCE_NAME \ |
| 49 | --quiet |
| 50 | ``` |
| 51 | |
| 52 | 5. **Get the instance connection name:** |
| 53 | |
| 54 | You need the instance connection name (which is formatted as |
| 55 | `PROJECT_ID:REGION:INSTANCE_NAME`) to connect using the Cloud SQL Auth |
| 56 | Proxy. Retrieve it with the following command: |
| 57 | |
| 58 | ```bash |
| 59 | gcloud sql instances describe INSTANCE_NAME \ |
| 60 | --format="value(connectionName)" \ |
| 61 | --quiet |
| 62 | ``` |
| 63 | |
| 64 | 6. **Connect to the instance:** |
| 65 | |
| 66 | The Cloud SQL Auth Proxy must be running to be able to connect to the |
| 67 | instance. In a separate terminal, start the proxy using the connection name: |
| 68 | |
| 69 | ```bash |
| 70 | ./cloud-sql-proxy INSTANCE_CONNECTION_NAME |
| 71 | ``` |
| 72 | |
| 73 | With the proxy running, connect using `psql` in another terminal: |
| 74 | |
| 75 | ```bash |
| 76 | psql "host=127.0.0.1 port=5432 user=postgres dbname=DATABASE_NAME password=PASSWORD sslmode=disable" |
| 77 | ``` |
| 78 | |
| 79 | ## Reference Directory |
| 80 | |
| 81 | - [Core Concepts](references/core-concepts.md): Instance architecture, high |
| 82 | availability (HA), and supported database engines. |
| 83 | |
| 84 | - [CLI Usage](references/cli-usage.md): Essential `gcloud sql` commands for |
| 85 | instance, database, and user management. |
| 86 | |
| 87 | - [Client Libraries & Connectors](references/client-library-usage.md): |
| 88 | Connecting to Cloud SQL using Python, Java, Node.js, and Go. |
| 89 | |
| 90 | - [MCP Usage](references/mcp-usage.md): Using the Cloud SQL remote MCP |
| 91 | server and Gemini CLI extension. |
| 92 | |
| 93 | - [Infrastructure as Code](references/iac-usage.md): Terraform |
| 94 | configuration for instances, databases, and users. |
| 95 | |
| 96 | - [IAM & Security](references/iam-security.md): Predefined roles, SSL/TLS |
| 97 | certificates, and Auth Proxy configuration. |
| 98 | |
| 99 | *If you need product information not found in these references, use the |
| 100 | Developer Knowledge MCP server `search_documents` tool.* |