Forbes India Leader Recognition
e.preventDefault(); // Prevent form submission input.blur(); // remove focus input.value = ""; // optional: clear the input

Connecting to Cloud SQL from Cloud Run

Connecting to Cloud SQL from Cloud Run

Featured Image

cloud-sql-cloud-run-1.png

What is Cloud SQL?

Cloud SQL is a MySQL database service that is hosted on Google Cloud and does not require any software installation and maintenance because the service is provided by Google Cloud. The Google Cloud should be maintained, managed and administered by itself.Just as regular MySQL database, Google Cloud SQL also lets you create, update, configure and utilize a relational database.

What is Cloud Run?

Cloud Run is a fully managed serverless execution environment and it takes care of all infrastructure management including provisioning, configuring, scaling, and managing servers.

Process for connecting to Cloud SQL from Cloud RUN:

In order to connect to a service running in a Cloud Run instance to a Cloud SQL for that you need to have your service containerized and uploaded to the Container Registry.

If you already have a containerized service in your container registry then try to move ahead by creating a Cloud SQL instance. Otherwise you need to build a containerized service and upload in the Container Registry.

Creating a Cloud SQL instance:

You can create a Cloud SQL instance by using the gcloud command as

gcloud sql instances create [INSTANCE_NAME] --tier=[MACHINE_TYPE] --region=[REGION]

For Example:

sql-instance-creation.png

gcloud sql instances create instance1 --tier=db-n1-standard-2 --region=europe-west2

Set the password for “root@%” MySQL user:

gcloud sql users set-password root --host=% --instance [INSTANCE_NAME] --password [PASSWORD]

Once the instance creation is done then you can find the INSTANCE_CONNECTION_NAME for the instance under the Instance details page. It uses the format PROJECT_ID:REGION:INSTANCE_ID.

Also, you have to enable the Cloud SQL Admin API, if it is not enabled already.

Configuring Cloud Run

You can configure Cloud Run using the Console or Command line. Here is the configuring process for Cloud Run using the Command line:

For deploying a new container, use the following command:

gcloud run deploy --image IMAGE --add-cloudsql-instances

INSTANCE-CONNECTION-NAME --set-env-vars

INSTANCE_CONNECTION_NAME=”INSTANCE-CONNECTION-NAME”

cloud-sql-cloud-run-3.png
For updating an existing service, use the following command:

gcloud run services update SERVICE-NAME --add-cloudsql-instances

INSTANCE-CONNECTION-NAME --set-env-vars

INSTANCE_CONNECTION_NAME=”INSTANCE-CONNECTION-NAME”

You need to change the following attributes in above commands while configuring the Cloud Run:

IMAGE – Replace with the image you are deploying

SERVICE-NAME –  Replace with the name of your Cloud Run service

INSTANCE-CONNECTION-NAME – Replace with the instance connection name of your Cloud SQL instance, or a comma delimiter list of connection names.

Cloud Run using a Service Account to authorize your connections to Cloud SQL and the service account which requires the correct IAM permissions to successfully connect. The default service account is in the format is PROJECT_NUMBER-compute@developer.gserviceaccount.com

Cloud SQL Connection:

Once done with the Cloud SQL configuration, then will connect service to the Cloud SQL instance by using the format as /cloudsql/INSTANCE_CONNECTION_NAME

For connecting to the Cloud SQL you need to setup the configuration. For more details regarding the configuration setup refer this link

The Connections are encrypted automatically without using any additional configuration.

Related Posts

Latest Posts

  • All Posts
  • AI Powered Knowledge
  • ai/ml
  • CEO India Magazine
  • CMMI level 5 Certification
  • e-learning
  • Fintech
  • gaming
  • Generative AI
  • healthcare
  • manufacturing
  • News
  • OTT
  • Portfolio
  • supply chain
  • travel and hospitality
  • Tudip's AI Hackathon
  • Voxlearn Enterprises
    •   Back
    • Android
    • iOS
    • Java
    • PHP
    • MEAN
    • Ruby
    • DotNet
    • IoT
    • Cloud
    • Testing
    • Roku
    • CMS
    • Python
The Future of Workplace Learning: AI-Powered Knowledge on Demand

The Future of Workplace Learning: AI-Powered Knowledge on Demand

June 12, 2026

A few months ago, I was sitting in a meeting with a team lead who looked genuinely frustrated. Not because…

Read More
We Built VoXlearn Because Enterprise Training Was Broken: Here’s What We Did About It

We Built VoXlearn Because Enterprise Training Was Broken: Here’s What We Did About It

June 12, 2026

If you’ve ever sat through an end-of-quarter training report and thought, “We spent all that time and money, and this…

Read More
We Did It Again: Tudip Successfully Renews Its CMMI Level 5 Certification

We Did It Again: Tudip Successfully Renews Its CMMI Level 5 Certification

June 9, 2026

Nobody around here needed a memo to know something worth celebrating had happened. The message from the CMMI Institute said…

Read More

India

Plot No. 11/2, Phase 3, Hinjewadi Rajiv Gandhi Infotech Park, Pune, India – 411057.
info@tudip.com
+91-96-8990-0537

United States

1999 S. Bascom Ave Suite 700, Campbell CA. 95008, USA.
info@tudip.com
+1-408-216-8162

Canada

64 Caracas Road North York, Toronto Ontario M2K 1B1, Canada.
info@tudip.com

Mexico

Calle Amado Nervo #785 Interior B Colonia Ladron De Guevara 44600 Guadalajara, Jalisco, Mexico.
info@tudip.com

Singapore

77 High Street, #10-12B High Street Plaza, Singapore 179433.
info@tudip.com

Colombia

Cra. 9 # 113-53 Of. 1405 Bogotá D.C., Colombia.
info@tudip.com

UAE

Tudip Information Technologies L.L.C Office No 109, ABU HAIL BUILDING 13, Abu Hail, Dubai, UAE.
info@tudip.com

Nigeria

22 Kumasi Crescent, Wuse 2, Abuja, Nigeria.
info@tudip.com