Run managed PostgreSQL or MySQL: create an instance, add a database and user, connect securely with the Cloud SQL proxy, scale the machine, and protect data with automated backups and on-demand backups.
Cloud SQL runs managed databases — PostgreSQL, MySQL, SQL Server. Why managed: Google handles patching, backups, and replication, so you get a database endpoint to connect to instead of a server to babysit. You still write normal SQL.
List the database versions Cloud SQL supports
gcloud sql tiers list 2>/dev/null | headecho "Engines: POSTGRES_16, MYSQL_8_0, SQLSERVER_2022_STANDARD, ..."A Cloud SQL "instance" is one running database server, sized by machine type. Why this takes a few minutes: Google provisions storage, networking, and the engine. This creates a real, billable PostgreSQL instance.
Create a small PostgreSQL instance
gcloud sql instances create learn-pg \
--database-version POSTGRES_16 \
--tier db-f1-micro \
--region us-central1 \
--root-password 'Ch00se-A-Strong-One!'Inside an instance you create databases (which hold tables) and users (which connect). Why separate from the root user: your app gets its own least-privilege login, so you can rotate or revoke it without touching the admin account.
Create a database
gcloud sql databases create appdb --instance learn-pgCreate an application user with its own password
gcloud sql users create appuser --instance learn-pg \
--password 'App-Strong-Pass!'Rather than opening the database to the internet, the Cloud SQL Auth Proxy creates a secure local tunnel authenticated by IAM. Why: your client connects to localhost while the proxy handles encryption and authorization — no public IP or IP allow-listing needed.
The simplest connect (opens a psql session through a secure channel)
gcloud sql connect learn-pg --user appuser --database appdbOr run the Auth Proxy yourself and point any client at localhost:5432 ./cloud-sql-proxy learn-gcp-7f3k:us-central1:learn-pg --port 5432
You can change an instance's machine type and storage without rebuilding it. Why: start small and cheap while learning, then move to a larger tier (more CPU/memory) when traffic grows. Storage can also auto-grow so you do not run out unexpectedly.
Move to a larger machine type and enable storage auto-grow
gcloud sql instances patch learn-pg \
--tier db-custom-2-7680 \
--storage-auto-increaseCloud SQL takes automated daily backups and supports point-in-time recovery; you can also take on-demand backups before risky changes. Why both: automated backups cover "undo the last few days"; on-demand backups are deliberate save points you restore from when needed.
Turn on automated daily backups (run at 03:00) and PITR
gcloud sql instances patch learn-pg \
--backup-start-time 03:00 \
--enable-point-in-time-recoveryTake an on-demand backup right now
gcloud sql backups create --instance learn-pg \
--description "before-migration"