多
Duoyun Cloud
BLOG

GCP Cloud SQL Database Deployment Guide

tutorials2026-04-18By Duoyun Cloud

A detailed guide to creating, configuring, and optimizing GCP Cloud SQL instances including high availability, performance tuning, and security hardening for production deployments.

GCPCloud SQLDatabaseDeployment

GCP Cloud SQL Database Deployment Guide

Databases are the backbone of application architecture. GCP Cloud SQL provides fully managed relational database services supporting MySQL, PostgreSQL, and SQL Server. This guide walks you through deploying a production-grade Cloud SQL instance on GCP.

Cloud SQL Overview

Engine Support

Engine Supported Versions Use Cases
MySQL 5.7, 8.0, 8.4 Web apps, e-commerce, CMS
PostgreSQL 13, 14, 15, 16 GIS, complex queries, JSON processing
SQL Server 2019, 2022 Enterprise ERP, .NET migrations

Comparison with Other Providers

Feature GCP Cloud SQL Alibaba Cloud RDS AWS RDS
MySQL version 8.4 8.0 8.0
Max storage 10 TB 6 TB 64 TB
Backup retention 365 days 730 days 35 days
Private connectivity Private Service Connect VPC Endpoint PrivateLink
Cross-region read replicas Yes Yes Yes
Free tier Yes (limited) No Yes (12 months)

Creating a Cloud SQL Instance

Console Creation

  1. Navigate to SQL → Create Instance
  2. Select the database engine (MySQL 8.0 in this example)
  3. Configure instance parameters:
Setting Recommendation (Production) Notes
Instance ID prod-mysql-primary Lowercase + hyphens
Password Strong + auto-rotation Enable password policy
DB version MySQL 8.0 Latest stable
Region asia-east1 (Taiwan) Closest to users
Machine type db-custom-4-16384 4 vCPU, 16 GB
Storage 100 GB SSD Enable auto-increase
HA Regional HA Cross-zone failover
Auto backup On, 02:00 UTC Retain 30 days
Private IP Enabled Access via VPC

gcloud CLI Creation

gcloud sql instances create prod-mysql-primary \
  --database-version=MYSQL_8_0 \
  --tier=db-custom-4-16384 \
  --region=asia-east1 \
  --storage-type=SSD \
  --storage-size=100GB \
  --storage-auto-increase \
  --availability-type=REGIONAL \
  --backup-start-time=02:00 \
  --enable-point-in-time-recovery \
  --network=projects/my-project/global/networks/my-vpc \
  --no-assign-ip

Machine Types and Pricing

Shared-Core Machines

Type vCPU Memory Monthly Cost (asia-east1) Use Case
db-f1-micro 1 (shared) 0.6 GB ~$7 Dev/test
db-g1-small 1 (shared) 1.7 GB ~$18 Lightweight apps

Custom Machine Types (Recommended)

Custom machine types let you independently select vCPU and memory for precise resource matching:

Config vCPU Memory Monthly (Single Zone) Monthly (HA)
db-custom-2-8192 2 8 GB ~$110 ~$220
db-custom-4-16384 4 16 GB ~$210 ~$420
db-custom-8-32768 8 32 GB ~$420 ~$840
db-custom-16-65536 16 64 GB ~$840 ~$1,680

Compared to Tencent Cloud TDSQL, Cloud SQL custom machines offer more flexible memory ratios (1:2 to 1:8), ideal for workloads with diverse requirements.

Storage Pricing

Storage Type Price (/GB/month) Performance Use Case
SSD $0.17 High IOPS OLTP production
HDD $0.11 Low IOPS Logs, archiving

High Availability Architecture

Regional HA

Cloud SQL HA uses a cross-zone primary-standby hot architecture:

Zone a: Primary ←sync replication→ Zone b: Standby
                ↑
         Automatic failover
  • RPO ≈ 0 (synchronous replication)
  • RTO ≈ 60–120 seconds
  • Additional cost: Compute doubles; storage does not

Cross-Region Disaster Recovery

Implement DR through cross-region read replicas:

gcloud sql instances create prod-mysql-dr \
  --master-instance-name=prod-mysql-primary \
  --region=asia-northeast1 \
  --tier=db-custom-4-16384

Cross-region replication is asynchronous, typically with sub-second lag. Cost includes cross-region network egress ($0.01/GB).

Read Replicas

Add read replicas for read-heavy applications:

gcloud sql instances create prod-mysql-replica1 \
  --master-instance-name=prod-mysql-primary \
  --region=asia-east1
Metric Details
Max replicas MySQL: 10, PostgreSQL: 20
Replication mode Asynchronous
Promotable to primary Yes
Connection Use replica IP

Networking and Connectivity

Private IP Connection (Recommended)

Compute Engine and GKE access Cloud SQL via VPC peering without public exposure:

  1. Specify VPC network during instance creation
  2. Allocate private IP range for Cloud SQL
  3. Use Private Service Connect or VPC peering

Cloud SQL Auth Proxy

The most secure connection method—no SSL certificate or IP allowlist management needed:

# Install Auth Proxy
wget https://dl.google.com/cloudsql/linux/amd64/cloud_sql_proxy
chmod +x cloud_sql_proxy

# Start proxy
./cloud_sql_proxy -instances=my-project:asia-east1:prod-mysql-primary=tcp:3306

Applications connect to localhost:3306 for secure database access.

Connection Pool Configuration

Parameter Recommended Value Notes
max_connections 4000 (4 vCPU instance) Default: vCPU × 1000
connect_timeout 10 seconds Prevent connection pile-up
wait_timeout 300 seconds Release idle connections promptly
Pool size CPU cores × 2 + disk spindles HikariCP recommendation

Backup and Recovery

Automatic Backups

  • Point-in-Time Recovery (PITR): Enable binlog retention to recover to any second
  • Retention: 7–365 days configurable
  • Cost: Backup storage $0.08/GB/month

Manual Backups and Exports

# Create on-demand backup
gcloud sql backups create --instance=prod-mysql-primary

# Export SQL to Cloud Storage
gcloud sql export sql prod-mysql-primary gs://my-bucket/backup.sql \
  --database=mydb

Recovery Operations

# Restore from backup (creates new instance)
gcloud sql backups restore BACKUP_ID --restore-instance=prod-mysql-restored

# Point-in-time recovery
gcloud sql instances clone prod-mysql-primary prod-mysql-pitr \
  --binlog-file-position=mysql-bin.000123,45678

Performance Optimization

Key Parameter Tuning

Parameter Default Recommended Notes
innodb_buffer_pool_size 128 MB 60–70% of physical memory Most critical parameter
innodb_log_file_size 48 MB 1–4 GB Reduce checkpoint frequency
innodb_flush_method fdatasync O_DIRECT Avoid double buffering
max_connections 4000 Adjust as needed Use with connection pool

Monitoring Metrics

Monitor these key metrics in Cloud Monitoring:

  • database/cpu/utilization — CPU utilization
  • database/disk/utilization — Disk usage
  • database/memory/utilization — Memory usage
  • database/network/connections — Connection count
  • database/mysql/innodb_buffer_pool_hit_ratio — Buffer pool hit ratio

Security Hardening

  1. Private IP only: Disable public access to the database
  2. Cloud IAM Authentication: MySQL 8.0+ supports IAM DB authentication
  3. SSL/TLS Encryption: Enforce SSL on all connections
  4. Data Encryption: Default Google-managed keys; CMEK also available
  5. Audit Logging: Enable Cloud SQL Admin API audit logs
  6. Maintenance Window: Schedule during low-traffic periods

Conclusion

GCP Cloud SQL delivers a reliable managed relational database solution with built-in HA and deep VPC integration. With proper instance sizing, Auth Proxy, and security configuration, you can build a production-grade database architecture.

Duoyun Cloud is an authorized GCP partner offering exclusive channel discounts on Cloud SQL and other GCP resources. Purchase through Duoyun for better-than-list pricing, Chinese-language technical consultants, and a unified multi-cloud management platform. Visit duoyun.io for discount details.

Back to Blog