Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

225
Views
Google cloud run cannot reach Cloud SQL

Everything was working fine just a moment ago but suddenly Google Cloud Run cannot connect with Cloud SQL. Both Cloud Run and Cloud SQL are in same project. Cloud SQL has public IP.

Cloud Run is running a containerized Django/uwsgi/nginx application. Getting following error:

MySQLdb._exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'xx.xxx.xx.xxx:3306' (110)")

Django settings:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': my_db_name,
        'USER': my_db_user,
        'PASSWORD': my_db_password,
        'HOST': cloud_sql_ip_address,
        'PORT': '3306',
    }
}

Below is the Cloud Run yaml piece:

annotations:
        run.googleapis.com/client-name: gcloud
        client.knative.dev/user-image: my_custom_manage
        run.googleapis.com/client-version: 347.0.0
        run.googleapis.com/cloudsql-instances: my_project_id:us-central1:my_sql_server
        autoscaling.knative.dev/maxScale: '10'
        run.googleapis.com/sandbox: gvisor

I have also checked this - https://cloud.google.com/sql/docs/mysql/connect-run

Service account that is attached to Cloud Run service have Compute Engine default service account which basically means it has all the access.

Solution: For anyone who may come to this question, use socket reference, not IP and Port. Since Cloud Run creates socket to connect to Cloud SQL and Django's IP:3306 doesn't work.

My update django DB settings:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': my_db_name,
        'USER': my_db_user,
        'PASSWORD': my_db_password,
        'HOST': f'/cloudsql/cloud_sql_connection_name'
    }
}

I am not sure though why it was working fine before with IP:3306, Cloud Run should have given error in the start itself.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Cloud Run uses an unix socket to connect to SQL.

From your error message, it looks like it tries to connect directly to the IP.

I would check the application code and see if there was an undetected update, the connection string should be based on a socket and not on an IP,

socket format is: /cloudsql/connection_id

See more here

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!