DEV Community

Hanzla Haroon
Hanzla Haroon

Posted on

How to setup proxy for Google Cloud SQL

In this tutorial, you will learn how to set up a proxy for your Google Cloud SQL instance and port it to local.

Pre-requisites:

  • An instance of Google Cloud SQL
  • Python 3 installed

Tutorial:

Step 1 Confirm that you have python3 installed by running the following command in the terminal.
python3 -V or python -V

Step 2 Check if you have gcloud cli installed on your machine by using the following command
gcloud auth application-default login

If you haven't you need to install it from here.

Step 3 Install gcloudSql auth proxy from here

Step 4 Run the following command in the terminal to log in with your Google account associated with gcloud SQL instance.
gcloud auth application-default login

Select your instance and region if it's necessary.

Step 5 After login, run the following command to port forward your instance to localhost.
./cloud-sql-proxy --address 0.0.0.0 --port <port> <db_instance_name>:<region>:<db_name>

Replace values with your required information. It will look like this.

./cloud-sql-proxy --address 0.0.0.0 --port 5674 hanzla-db-369715:us-central1:postgres

Step 6 Voila! Your gcloud SQL instance is accessible on port 5674 on your local machine. Connect your backend with db on this path or connect it with a database visualizer like DBeaver to explore the database.

Top comments (0)