Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

226
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda