Score:0

unable to connect mysql from gcloud app deployment

jp flag

Getting below error while trying to communicate mysql database from gcloud django app deploy. Below is the error message:

OperationalError at /
(2002, "Can't connect to local MySQL server through socket '/cloudsql/aevolveai-app-beta:us-central1:mysqlocr-uat1' (111)")

Please advise how to resolve it, sorry I am new to gcloud and serverfault

ca flag
Is the mysql server running on the same host as your app? If not, is it configured to allow connections from remote hosts?
Sangram Sinha avatar
jp flag
Yes, i copied the connection name from gcloud sql engine. I can connect to mysql database from gcloud console by using below command **gcloud sql connect mysqlocr-uat1 --user=root** But I am not able to understand why I am now able to connect from my hosted application. I have made below changes in my django setting.py file. ** 'ENGINE': 'django.db.backends.mysql', 'HOST': '/cloudsql/aevolveai-app-beta:us-central1:mysqlocr-uat1', 'USER': 'root', 'PASSWORD': , 'NAME': '_ocrmysqluat1', **
Sangram Sinha avatar
jp flag
I found something, my python version it is showing as 2.7 in gcloud console. Can you please let me know how to update it. even pip is not installed and when I am trying to install it I a facing below error. **Traceback (most recent call last): File "/usr/bin/pip", line 5, in <module> from pip._internal.cli.main import main ModuleNotFoundError: No module named 'pip'**
Sangram Sinha avatar
jp flag
I fixed this version problem but still getting the same error
Score:0
co flag

you are using a Cloud SQL instance according to your comments. to connect to it you need:

  • proper service account authorization
  • proper connection between your workload and the SQL if your workload is not in a VM but is deployed into a PaaS (like cloud run) additional steps must be followed like VPC private connector setup.

btw once the 'basic' connection works, it is recommended that you you the cloud sql proxy tool to connect and authenticate into the Cloud SQL instance

Sangram Sinha avatar
jp flag
Thanks for your advice..I talked to one of the gcloud support member and they fixed the issue. And yes, there was an issue on proper service account authorization so as they suggested I show add service account details in app.yml and it worked.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.