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.

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay