cloud-sql-basics

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Cloud SQL Basics

Cloud SQL 基础

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.
Cloud SQL是一款针对MySQL、PostgreSQL和SQL Server的全托管关系型数据库服务。它可自动完成补丁更新、备份、副本创建等耗时任务,同时为您的应用提供高性能和高可用性。

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.
确保您拥有创建和管理Cloud SQL实例所需的IAM权限。Cloud SQL管理员
roles/cloudsql.admin
)角色可提供对Cloud SQL资源的完全访问权限。

Quick Start (PostgreSQL)

快速入门(PostgreSQL)

  1. Enable the API:
    bash
    gcloud services enable sqladmin.googleapis.com
  2. Create an Instance:
    bash
    gcloud sql instances create INSTANCE_NAME \
      --database-version=POSTGRES_18 \
      --cpu=2 \
      --memory=7680MiB \
      --region=REGION
  3. Set a password for the default user:
    Because this is a Cloud SQL for PostgreSQL instance, the default admin user is
    postgres
    :
    bash
    gcloud sql users set-password postgres \
      --instance=INSTANCE_NAME --password=PASSWORD
  4. Create a database:
    bash
    gcloud sql databases create DATABASE_NAME \
      --instance=INSTANCE_NAME
  5. 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:
    bash
    gcloud sql instances describe INSTANCE_NAME \
      --format="value(connectionName)"
  6. 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:
    bash
    ./cloud-sql-proxy INSTANCE_CONNECTION_NAME
    With the proxy running, connect using
    psql
    in another terminal:
    bash
    psql "host=127.0.0.1 port=5432 user=postgres dbname=DATABASE_NAME password=PASSWORD sslmode=disable"
  1. 启用API:
    bash
    gcloud services enable sqladmin.googleapis.com
  2. 创建实例:
    bash
    gcloud sql instances create INSTANCE_NAME \
      --database-version=POSTGRES_18 \
      --cpu=2 \
      --memory=7680MiB \
      --region=REGION
  3. 为默认用户设置密码:
    由于这是Cloud SQL for PostgreSQL实例,默认管理员用户为
    postgres
    bash
    gcloud sql users set-password postgres \
      --instance=INSTANCE_NAME --password=PASSWORD
  4. 创建数据库:
    bash
    gcloud sql databases create DATABASE_NAME \
      --instance=INSTANCE_NAME
  5. 获取实例连接名称:
    您需要实例连接名称(格式为
    PROJECT_ID:REGION:INSTANCE_NAME
    )才能使用Cloud SQL Auth Proxy进行连接。使用以下命令获取:
    bash
    gcloud sql instances describe INSTANCE_NAME \
      --format="value(connectionName)"
  6. 连接到实例:
    必须运行Cloud SQL Auth Proxy才能连接到实例。在单独的终端中,使用连接名称启动代理:
    bash
    ./cloud-sql-proxy INSTANCE_CONNECTION_NAME
    代理运行后,在另一个终端中使用
    psql
    进行连接:
    bash
    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.
  • 核心概念:实例架构、高可用性(HA)和支持的数据库引擎。
  • CLI使用指南:用于实例、数据库和用户管理的重要
    gcloud sql
    命令。
  • 客户端库与连接器:使用Python、Java、Node.js和Go连接到Cloud SQL。
  • MCP使用指南:使用Cloud SQL远程MCP服务器和Gemini CLI扩展。
  • 基础设施即代码:用于实例、数据库和用户的Terraform配置。
  • IAM与安全:预定义角色、SSL/TLS证书和Auth Proxy配置。
如果您在这些参考资料中找不到所需的产品信息,请使用开发者知识MCP服务器的
search_documents
工具。