2
votes

I am trying to use Flask SQLAlchemy to establish a database connection between Google App Engine and Google Cloud SQL.

I am able to establish the connection in a Flex environment but not Standard whenever I deploy. I am not sure why this is the case. I am receiving this error response from the Error Logs:

OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on 'localhost' ([Errno 97] Address family not supported by protocol)")

This is the connection string I am using to connect to the Cloud SQL database app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://<username>:<password>@/<database>?unix_socket=/cloudsql/<instanceName>'

When testing and developing locally, I am able to use this connection string to connect to the database through the cloud_sql_proxy but this connection string fails when I deploy and attempt to access it externally.

I've looked through similar questions but haven't seen any that reference this specific error response yet.

I am using the Second Gen Cloud SQL version

Where do you specify the host name in this line:app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://<username>:<password>@/<database>?unix_socket=/cloudsql/<instanceName>'? - kip2
It is specified with <database> - Quentin