【发布时间】:2019-01-24 23:15:36
【问题描述】:
我在 settings.py 中设置了 mySQL 数据库,如下所示:
if os.getenv('GAE_APPLICATION', None):
# Running on production App Engine, so connect to Google Cloud SQL using
# the unix socket at /cloudsql/<your-cloudsql-connection string>
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/myApp:europe-west1:myApp-instance',
'NAME': 'myApp',
'USER': 'myApp',
'PASSWORD': 'myApp', }}
else:
# Running locally so connect to either a local MySQL instance or connect to
# Cloud SQL via the proxy. To start the proxy via command line:
#
# $ ./cloud_sql_proxy -instances="myApp:europe-west1:myApp-instance"=tcp:3306
#
# See https://cloud.google.com/sql/docs/mysql-connect-proxy
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '127.0.0.1',
'PORT': '3306',
'NAME': 'myApp',
'USER': 'myApp',
'PASSWORD': 'myApp', }}
当我想在本地运行 myApp 时,我必须先在终端上运行这个命令:
./cloud_sql_proxy -instances="myApp:europe-west1:myApp-instance"=tcp:3306
这很烦人...有办法将它集成到我的代码中吗?
例如,我会在设置中添加一些自动运行命令的内容,紧跟在“else:”之后 但我不知道我要写什么......有什么想法吗?有可能吗?
【问题讨论】:
标签: python mysql django google-app-engine proxy