I'm building a django (1.9) app using cloudsql and a 'new' flexible environment. I have this same error: Django on Google AppEngine with CloudSQL: How to connect database (Error 2002, Can't connect to local MySQL server..)
However, in that thread, they refer to docs which are older and explain to put the database key ,HOST, in the format:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/myapp-test01:myapp-db-test01',
'NAME': 'test01',
'USER': 'test01',
}
Whereas in the documentation for running django on the 'flexible' environment, it is explained to open your database to the world (0.0.0.0/0) and use the format:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '<your-database-name>',
'USER': '<your-database-user>',
'PASSWORD': '<your-database-password>',
'HOST': '<your-database-host>',
'PORT': '3306',
}
}
Where is presumably the IP address given by CloudSQL.
Please see the docs here: https://cloud.google.com/python/django/flexible-environment
Note the 'Flexible Environment' which seems to be distinctly different (but I don't know why).
I'm writing, because I when I change from IP address format to /cloudsq/... format I get the error
OperationalError: (2002, "Can't connect to local MySQL server through socket '/cloudsql/desgn-test-01:db-test-01' (2)")
Any advice is highly appreciated. It seems impossible that google really expects us to leave databases open to 0.0.0.0, and in the docs they even say it is only for testing but provide no further information.
I should also mention, I'm using two databases in my django config and the 'default' one is a sqlite db (this part of the site is working fine). I get the error when I try to connect to my app that is using the cloud sql parameter. This ONLY happens when deployed, locally everything works perfect.