cloud-sql-basics
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCloud 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 () role provides full
access to Cloud SQL resources.
roles/cloudsql.admin确保您拥有创建和管理Cloud SQL实例所需的IAM权限。Cloud SQL管理员()角色可提供对Cloud SQL资源的完全访问权限。
roles/cloudsql.adminQuick Start (PostgreSQL)
快速入门(PostgreSQL)
-
Enable the API:bash
gcloud services enable sqladmin.googleapis.com -
Create an Instance:bash
gcloud sql instances create INSTANCE_NAME \ --database-version=POSTGRES_18 \ --cpu=2 \ --memory=7680MiB \ --region=REGION -
Set a password for the default user:Because this is a Cloud SQL for PostgreSQL instance, the default admin user is:
postgresbashgcloud sql users set-password postgres \ --instance=INSTANCE_NAME --password=PASSWORD -
Create a database:bash
gcloud sql databases create DATABASE_NAME \ --instance=INSTANCE_NAME -
Get the instance connection name:You need the instance connection name (which is formatted as) to connect using the Cloud SQL Auth Proxy. Retrieve it with the following command:
PROJECT_ID:REGION:INSTANCE_NAMEbashgcloud sql instances describe INSTANCE_NAME \ --format="value(connectionName)" -
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_NAMEWith the proxy running, connect usingin another terminal:psqlbashpsql "host=127.0.0.1 port=5432 user=postgres dbname=DATABASE_NAME password=PASSWORD sslmode=disable"
-
启用API:bash
gcloud services enable sqladmin.googleapis.com -
创建实例:bash
gcloud sql instances create INSTANCE_NAME \ --database-version=POSTGRES_18 \ --cpu=2 \ --memory=7680MiB \ --region=REGION -
为默认用户设置密码:由于这是Cloud SQL for PostgreSQL实例,默认管理员用户为:
postgresbashgcloud sql users set-password postgres \ --instance=INSTANCE_NAME --password=PASSWORD -
创建数据库:bash
gcloud sql databases create DATABASE_NAME \ --instance=INSTANCE_NAME -
获取实例连接名称:您需要实例连接名称(格式为)才能使用Cloud SQL Auth Proxy进行连接。使用以下命令获取:
PROJECT_ID:REGION:INSTANCE_NAMEbashgcloud sql instances describe INSTANCE_NAME \ --format="value(connectionName)" -
连接到实例:必须运行Cloud SQL Auth Proxy才能连接到实例。在单独的终端中,使用连接名称启动代理:bash
./cloud-sql-proxy INSTANCE_CONNECTION_NAME代理运行后,在另一个终端中使用进行连接:psqlbashpsql "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: Essentialcommands for instance, database, and user management.
gcloud sql -
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 tool.
search_documents-
核心概念:实例架构、高可用性(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