Agares
Agares

Reputation: 59

Error connecting GCP App Engine to GCP SQL

I'm trying to deploy a Flask App on the App Engine, but I'm getting this error about the database connection:

sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)")

I'm doing the connection like this:

databaseUri = 'mysql+pymysql://user:pass@/database?unix_socket=/cloudsql/connection_name'

Also activated the Cloud SQL Administrator API as the documentation says, but not working

Does anyone have an idea about what am I missing or doing wrong?

I've have been stuck on this for 2 days and I can't make it work, thanks for your help.

Upvotes: 0

Views: 102

Answers (1)

Agares
Agares

Reputation: 59

I solved it.

I post the solution maybe helps someone else.

I still don't know why, but when running the command to deploy the app in the App Engine:

gcloud app deploy

It use by default the Compute Engine service account instead of the App Engine service account, so I just had to run the command specifying it to use the App Engine service account:

gcloud app deploy --service-account=SERVICE_ACCOUNT

Hope it helps any newbe like me.

Upvotes: 2

Related Questions