Connect to Cloud SQL với Cloud SQL Auth Proxy:

//install cloud-sql-proxy
brew install cloud-sql-proxy

// must be know region example: asia-southeast1

//check
cloud-sql-proxy --version

//gcp login
gcloud auth login

//set app default if need
gcloud auth application-default login

# Start proxy
cloud_sql_proxy PROJECT:REGION:INSTANCE --port=5432

cloud-sql-proxy deep-freehold-437008-j5:us-central1:my-first-cloud-sql-database --port=5432 --debug-logs

cloud-sql-proxy deep-freehold-437008-j5:us-central1:my-first-cloud-sql-database --port=5555

# Cloud SQL
gcloud sql connect my-first-cloud-sql-instance --user=root --quiet
gcloud config set project glowing-furnace-304608
gcloud sql connect my-first-cloud-sql-instance --user=root --quiet

Create Table:

# Cloud SQL
use todos
create table user (id integer, username varchar(30) );
describe user;
insert into user values (1, 'Sol Lee');
select * from user;

Cloud SQL:

  1. Full managed relational db:
  2. Use for simple relational use cases, sử dụng Cloud Spanner nếu cần huge volumes Relational DB || infinite scaling || Global DB || Availability (99.999%)

Important Cloud SQL Feature:

  1. Auto encryption (table, backups), auto maintenance, and updates.
  2. High availability and failover (chuyển đổi dự phòng) required: automated backups and binary logging.
  3. Read replicas for read workloads: Cross-zone(region) and external(non cloud sqldb) required: automated backups and binary logging.
  4. auto storage increase with downtime (new ver)
  5. point-in-time recovery: enable binary logging.
  6. Supports migration from other sources Use Database Migration Service (DMS) You can export data from UI (console) or gcloud with formats: SQL (Recommended if you import data into other databases) and CSV