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:
- Full managed relational db:
- Config your needs, NOT worry about managing db.
- Support MySQL, PostgreSQL, SQL server.
- Availability (99.95%)
- SSDs & HDDs (use SSDs for best performance)
- Upto 416 GB RAM and 30TB storage.
- 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:
- Auto encryption (table, backups), auto maintenance, and updates.
- High availability and failover (chuyển đổi dự phòng) required: automated backups and binary logging.
- Read replicas for read workloads: Cross-zone(region) and external(non cloud sqldb) required: automated backups and binary logging.
- auto storage increase with downtime (new ver)
- point-in-time recovery: enable binary logging.
- 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