I am using a Cloud SQL Second generation. Django is running on the appspot, and connection to the database is working fine when testing on the localhost. I can also connect with the mysql client to the instance remotely, create databases, create users, the usual stuff. I can even remotely upload fixtures.
But I am unable to get django on the appspot connected to the SQL instance.
When trying this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'INSTANCE': 'instance:connection:name',
'NAME': 'database',
'USER': 'dbuser',
'PASSWORD': 'pass',
}
}
I get an OperationalError
:
(2001, "Can't create UNIX socket (-1)")
When trying this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'database',
'USER': 'dbuser',
'PASSWORD': 'pass',
'HOST': '1.2.3.4', # my SQL instance IPv4 address
}
}
I get an OperationalError
:
(2004, "Can't create TCP/IP socket (-1)")
When trying this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'database',
'USER': 'dbuser',
'PASSWORD': 'pass',
'HOST': '/cloudsql/my-instance-id',
}
}
I get an OperationalError
:
(2013, "Lost connection to MySQL server at 'reading initial communication packet', system error: 38")
What are the DATABASES
settings to use for django when using a Google Cloud SQL Second Generation?
EDIT
There is a page describing the required settings, but I would say that is for First Generation.
Also, there is a related question, but that applies also for First Generation.
EDIT2
I have seen that by default there are no "Authorized applications" for Cloud SQL Second Generation, and there is no option to authorize an application on the Google Cloud Platform console. This could be the reason why connections are not working. Unfortunately I do not yet know how to authorize an application for Second Generation instances.
EDIT3
Trying to authorize applications:
gcloud sql instances patch <sql-instance> --authorized-gae-apps <gae-app>
But unfortunately:
ERROR: (gcloud.sql.instances.patch) Failed to update an instance because it exceeded the maximum number of app IDs that can be attached to the instance.
No idea how to this for Second Generation