There are three type of connections:
1) your dev machine to your local mysql instance (Easy!)
2) your app engine instance (in Google Cloud) to Google Cloud SQL instance (the same way described in the document)
3) your dev machine to cloudsql instance (Hard): the encouraged way is to obtain an static IP (for a while that doesn't cost you much money), and use the IP to connect cloudsql instance.
Django code [3] should allow you switch between above cases. The command [1] allows you to syncdb to cloudsql instance. If you want your django model to manipulate data in cloudsql instance, you can add config [2] to app.yaml
[1]
SETTING_MODE=prod ./manage.py syncdb
[2]
env_variables:
SETTINGS_MODE: prod
[3]
import os
if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine'):
# Running on production App Engine, so use a Google Cloud SQL database.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/your-project-id:your-instance-name',
'NAME': 'django_test',
'USER': 'root',
}
}
elif os.getenv('SETTINGS_MODE') == 'prod':
# Running in development, but want to access the Google Cloud SQL instance
# in production.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': 'static-ip-of-cloudsql-instance',
'PORT': '3306',
'NAME': 'django_test',
'USER': 'username',
'PASSWORD': 'password'
}
}
else:
# Running in development, so use a local MySQL database.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django_test',
'USER': 'root',
'PASSWORD': 'root',
}
}