0
0
GcpHow-ToBeginner · 3 min read

How to Create a Cloud SQL Instance on Google Cloud Platform

To create a Cloud SQL instance on Google Cloud Platform, use the gcloud sql instances create command with your instance name and configuration options like database version and region. This sets up a managed SQL database instance ready for use.
📐

Syntax

The basic command to create a Cloud SQL instance is:

gcloud sql instances create INSTANCE_NAME --database-version=DATABASE_VERSION --tier=MACHINE_TYPE --region=REGION

Explanation of parts:

  • INSTANCE_NAME: Your chosen name for the SQL instance.
  • DATABASE_VERSION: The SQL engine version, e.g., MYSQL_8_0, POSTGRES_14.
  • MACHINE_TYPE: The machine tier, like db-f1-micro or db-n1-standard-1, defining resources.
  • REGION: The GCP region where the instance will be created, e.g., us-central1.
bash
gcloud sql instances create my-instance --database-version=MYSQL_8_0 --tier=db-f1-micro --region=us-central1
💻

Example

This example creates a MySQL 8.0 Cloud SQL instance named my-instance in the us-central1 region with a small machine type.

bash
gcloud sql instances create my-instance --database-version=MYSQL_8_0 --tier=db-f1-micro --region=us-central1
Output
Created [https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/my-instance]. NAME REGION DATABASE_VERSION TIER STATE my-instance us-central1 MYSQL_8_0 db-f1-micro RUNNABLE
⚠️

Common Pitfalls

  • Not specifying the --region can cause the command to fail or create the instance in an undesired location.
  • Choosing an unsupported --database-version or --tier leads to errors.
  • Using an instance name that already exists in your project will cause a conflict.
  • Forgetting to enable the Cloud SQL Admin API in your GCP project will block instance creation.
bash
Wrong:
gcloud sql instances create my-instance --database-version=MYSQL_5_6 --tier=unsupported-tier

Right:
gcloud sql instances create my-instance --database-version=MYSQL_8_0 --tier=db-f1-micro
📊

Quick Reference

Remember these key points when creating a Cloud SQL instance:

  • Always specify --database-version, --tier, and --region.
  • Use a unique instance name within your project.
  • Enable the Cloud SQL Admin API before creating instances.
  • Check available machine types and database versions in your region.

Key Takeaways

Use the gcloud CLI command 'gcloud sql instances create' with required flags to create a Cloud SQL instance.
Specify database version, machine tier, and region to avoid errors and ensure proper configuration.
Enable the Cloud SQL Admin API in your GCP project before creating instances.
Choose a unique instance name to prevent conflicts.
Check available options for machine types and database versions in your chosen region.