chore: import upstream snapshot with attribution
Component Security Validation / Security Audit (push) Has been cancelled
Deploy to Cloudflare Pages / deploy (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 12:38:58 +08:00
commit bb5c75ce05
8824 changed files with 1946442 additions and 0 deletions
@@ -0,0 +1,84 @@
# Cloud SQL CLI Usage
The `gcloud sql` command group is used to manage Cloud SQL instances and
related resources.
## Basic Syntax
```bash
gcloud sql [GROUP] [COMMAND] [FLAGS]
```
## Essential Commands
### Instance Management
- **Create an instance:**
```bash
gcloud sql instances create my-instance --database-version=MYSQL_8_0 \
--tier=db-f1-micro --region=us-central1 \
--quiet
```
- **List instances:**
```bash
gcloud sql instances list --quiet
```
- **Describe an instance:**
```bash
gcloud sql instances describe my-instance --quiet
```
- **Restart an instance:**
```bash
gcloud sql instances restart my-instance --quiet
```
### Database and User Management
- **Create a database:**
```bash
gcloud sql databases create my-db --instance=my-instance --quiet
```
- **Create a user:**
```bash
gcloud sql users create my-user --instance=my-instance \
--password=my-password \
--quiet
```
### Operations and Backups
- **List operations:**
```bash
gcloud sql operations list --instance=my-instance --quiet
```
- **Create a backup:**
```bash
gcloud sql backups create --instance=my-instance --quiet
```
- **Restore from a backup:**
```bash
gcloud sql backups restore backup_id --restore-instance=my-instance --quiet
```
## Common Flags
- `--project`: Specifies the project ID.
- `--region`: The region where the instance is located.
- `--format`: Changes output format (e.g., `json`, `yaml`).
@@ -0,0 +1,116 @@
# Cloud SQL Client Libraries
Google Cloud provides client libraries and connectors to simplify connecting to
Cloud SQL from various programming languages.
## Getting Started
Ensure you have the latest version of the Google Cloud SDK installed and
authenticated.
[Install Google Cloud SDK](https://cloud.google.com/sdk/docs/install)
### Language Connectors
The Cloud SQL Language Connectors (Python, Java, Go, Node.js) provide a secure
way to connect to the Cloud SQL instance without managing IP allowlists or SSL
certificates.
#### Python
- **Installation for a Cloud SQL for PostgreSQL instance:**
```bash
pip install "cloud-sql-python-connector[pg8000]"
```
- **Usage Example:**
```python
from google.cloud.sql.connector import Connector
connector = Connector()
def getconn():
conn = connector.connect(
"project:region:instance",
"pg8000",
user="my-user",
password="my-password",
db="my-db"
)
return conn
```
#### Java
- **Maven Dependencies:**
The recommended method is to use the Cloud SQL JDBC Socket Factory. Add the
BOM to your `<dependencyManagement>` section:
```xml
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>jdbc-socket-factory-bom</artifactId>
<version>1.18.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
```
Then add dependencies for your database:
* **PostgreSQL:**
```xml
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.3</version>
</dependency>
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>postgres-socket-factory</artifactId>
</dependency>
</dependencies>
```
* **MySQL:**
```xml
<dependencies>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.0.33</version>
</dependency>
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>mysql-socket-factory-connector-j-8</artifactId>
</dependency>
</dependencies>
```
#### Node.js (TypeScript)
- **Installation:**
```bash
npm install @google-cloud/cloud-sql-connector
```
#### Go
- **Installation:**
```bash
go get cloud.google.com/go/cloudsqlconn
```
## Cloud SQL Admin API
To manage Cloud SQL resources (e.g., list instances) programmatically, use the
`sqladmin` libraries.
- [Cloud SQL Admin API Overview](https://docs.cloud.google.com/sql/docs/mysql/admin-api)
@@ -0,0 +1,62 @@
# Cloud SQL Core Concepts
Cloud SQL provides managed relational databases, abstracting the underlying
infrastructure while offering standard database engines.
## Supported Engines
Cloud SQL supports the following database engines (see [supported
versions](https://docs.cloud.google.com/sql/docs/db-versions)):
- **MySQL:** Versions 5.6, 5.7, 8.0, and 8.4.
- **PostgreSQL:** Versions 9.6, 10, 11, 12, 13, 14, 15, 16, 17, and 18
(default).
- **SQL Server:** 2017 (Express, Web, Standard, Enterprise), 2019, 2022, and
2025 (Express, Enterprise, Standard).
## Instance Architecture
Each Cloud SQL instance is powered by a virtual machine (VM) running the
database program.
- **Primary Instance:** The main read/write connection point.
- **High Availability (HA):** Provides a standby VM in a different zone with
automatic failover.
- **Read Replicas:** Used to scale read traffic and provide local access in
different regions.
## Storage and Networking
- **Persistent Disk:** Scalable and durable network storage attached to the
VM.
- **Connectivity:** Supports Private IP (using VPC peering for MySQL and
PostgreSQL only; or using private services access or Private Service Connect
for all Cloud SQL engines) and Public IP (with authorized networks or Auth
Proxy).
## Pricing
Cloud SQL pricing is based on:
- **Instance Type:** vCPUs and RAM.
- **Storage:** Amount of data stored and IOPS.
- **Networking:** Network egress and IP address usage.
- **DNS pricing:** Charge is per zone per month (regardless of whether you use
your zone). You also pay for queries against your zones.
- **Licensing:** Applies to SQL Server only. In addition to instance and
resource pricing, SQL Server also has a licensing component. High
availability, or regional instances, will only incur the cost for a single
license for the active resource. As a managed service, Cloud SQL does not
support BYOL (Bring your own license).
For the latest pricing, visit: [Cloud SQL
Pricing](https://cloud.google.com/sql/pricing).
@@ -0,0 +1,46 @@
# Cloud SQL Infrastructure as Code
Cloud SQL resources can be provisioned and managed using Terraform and other IaC
tools.
## Terraform
The Google Cloud Terraform provider supports Cloud SQL instances, databases, and
users.
### Cloud SQL Instance Example
```terraform
resource "google_sql_database_instance" "default" {
name = "master-instance"
region = "us-central1"
database_version = "POSTGRES_15"
settings {
tier = "db-f1-micro"
backup_configuration {
enabled = true
}
}
}
resource "google_sql_database" "database" {
name = "my-database"
instance = google_sql_database_instance.default.name
}
resource "google_sql_user" "users" {
name = "me"
instance = google_sql_database_instance.default.name
password = "changeme"
}
```
### Reference Documentation
- [Terraform Google Provider - SQL Database Instance](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance)
- [Terraform Google Provider - SQL Database](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database)
- [Terraform Google Provider - SQL User](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_user)
@@ -0,0 +1,67 @@
# Cloud SQL IAM & Security
Cloud SQL uses Identity and Access Management (IAM) to control access to
instances and databases.
## Predefined IAM Roles
| Predefined Role | Usage |
| :--- | :--- |
| `roles/cloudsql.admin` | Full control over all Cloud SQL resources. |
| `roles/cloudsql.editor` | Manage Cloud SQL resources. Cannot see or modify
permissions, nor modify users or ssl Certs. Cannot import data or restore from
a backup, nor clone, delete, or promote instances. Cannot start or stop
replicas. Cannot delete databases, replicas, or backups. |
| `roles/cloudsql.viewer` | Read-only access to Cloud SQL resources. |
| `roles/cloudsql.client` | Connectivity access to Cloud SQL instances from App
Engine and the Cloud SQL Auth Proxy. Not required for accessing an instance
using IP addresses. |
| `roles/cloudsql.instanceUser` | Permission to log in to a Cloud SQL
instance. |
| `roles/cloudsql.schemaViewer` | Role allowing access to a Cloud SQL instance
schema in Knowledge Catalog. |
| `roles/cloudsql.studioUser` | Role allowing access to Cloud SQL Studio. |
## Secure Connectivity
- **Cloud SQL Auth Proxy:** The recommended way to connect securely. It
provides IAM-based authentication and end-to-end encryption without
requiring SSL/TLS certificates or authorized networks.
- **Private IP:** Use VPC, private services access, or Private Service Connect
(PSC) to keep database traffic within the Google Cloud network.
- **Authorized Networks:** If using Public IP, restrict access to specific
CIDR ranges.
## Data Security
- **Encryption at Rest:** All data is encrypted by default. Use
Customer-Managed Encryption Keys (CMEK) for additional control.
- **IAM Database Authentication:** Authenticate to the database using IAM
users or service accounts instead of static passwords (available for MySQL
and PostgreSQL).
## Organization Policies
- **Cloud SQL organization policies:** Organization policies let organization
administrators set restrictions on how users can configure instances under
that organization.
## Service Accounts
- **Service Identity:** Cloud SQL uses an instance service account
(`p[PROJECT_NUMBER]-[UNIQUE_ID]@gcp-sa-cloud-sql.iam.gserviceaccount.com`)
for tasks like exporting a SQL dump file to Cloud Storage. Service agent
accounts (`service-PROJECT_NUMBER@gcp-sa-cloud-sql.iam.gserviceaccount.com`)
are used only for internal management tasks.
- **App Connectivity:** Grant the service account running your app (e.g., on
Cloud Run or GKE) the `roles/cloudsql.client` role.
For more information, see:
- [About Access Control - Cloud SQL for MySQL](https://docs.cloud.google.com/sql/docs/mysql/instance-access-control)
- [About Access Control - Cloud SQL for PostgreSQL](https://docs.cloud.google.com/sql/docs/postgres/instance-access-control)
- [About Access Control - Cloud SQL for SQL Server](https://docs.cloud.google.com/sql/docs/sqlserver/instance-access-control)
@@ -0,0 +1,51 @@
# Cloud SQL MCP Usage
Cloud SQL can be managed via the Model Context Protocol (MCP), which allows
agents to manage database instances and execute SQL queries. MCP is available
via remote servers and through local execution with the MCP Toolbox:
* [Cloud SQL for PostgreSQL](https://mcp-toolbox.dev/integrations/cloud-sql-pg/source/)
* [Cloud SQL for MySQL](https://mcp-toolbox.dev/integrations/cloud-sql-mysql/source/)
* [Cloud SQL for SQL Server](https://mcp-toolbox.dev/integrations/cloud-sql-mssql/source/)
## MCP Tools for Cloud SQL
The Cloud SQL MCP server typically includes the following tools:
- `clone_instance`: creates a Cloud SQL instance as a clone of source
instance.
- `create_instance`: initiates the creation of a Cloud SQL instance.
- `create_user`: creates a database user for a Cloud SQL instance.
- `execute_sql`: executes any valid SQL statements (DDL, DCL, DQL, DML) on a
Cloud SQL instance.
- `get_instance`: gets the details of a Cloud SQL instance.
- `get_operation`: gets the status of a long-running operation in Cloud SQL.
- `list_instances`: lists all Cloud SQL instances in a project.
- `list_users`: lists all database users for a Cloud SQL instance.
- `import_data`: imports data into a Cloud SQL instance from Cloud Storage.
- `update_instance`: updates supported settings of a Cloud SQL instance.
- `update_user`: updates a database user for a Cloud SQL instance.
For additional specialized skills including health auditing, performance
monitoring, and lifecycle management, install the Gemini CLI extension or Claude
Plugin:
* [Cloud SQL for PostgreSQL](https://github.com/gemini-cli-extensions/cloud-sql-postgresql)
* [Cloud SQL for MySQL](https://github.com/gemini-cli-extensions/cloud-sql-mysql)
* [Cloud SQL for SQL Server](https://github.com/gemini-cli-extensions/cloud-sql-sqlserver)
## Setup Instructions
Setup varies by database engine and whether you are connecting to a remote
server or using the MCP Toolbox. For remote server setup, see Setting up
Cloud SQL MCP for [PostgreSQL](https://docs.cloud.google.com/sql/docs/postgres/use-cloudsql-mcp),
[MySQL](https://docs.cloud.google.com/sql/docs/mysql/use-cloudsql-mcp), or
[SQL Server](https://docs.cloud.google.com/sql/docs/sqlserver/use-cloudsql-mcp).
## Supported Operations
Agents using the Cloud SQL MCP can:
- Automate database schema migrations.
- Perform health checks and monitor operation logs.
- Assist in debugging SQL performance issues.