我正在尝试将Loopback应用程序部署到Google Cloud中的Flexible引擎,将其连接到位于Google CloudSQL实例中的MySQL数据库,但是我不能。当我尝试部署应用程序时,总是会出现相同的错误:
Web server listening at: http://localhost:8080
Connection fails: Error: getaddrinfo ENOTFOUND /cloudsql/miampa-1be3e:us-central1:miampa-prueba2 /cloudsql/miampa-1be3e:us-central1:miampa-prueba2:3306
It will be retried for the next request.
events.js:183
throw er; // Unhandled 'error' event
我的datasources.json
是:
{
"db": {
"name": "db",
"connector": "memory"
},
"appAmpa": {
"name": "appAmpa",
"connector": "mysql",
"host": "/cloudsql/miampa-1be3e:us-central1:miampa-prueba2",
"database": "prueba",
"user": "root",
"password": "XXXXXX"
}
}
,在Loopback应用程序的根文件夹中,我有app.yaml文件:
[START app_yaml]
runtime: nodejs
env: flex
beta_settings:
cloud_sql_instances: miampa-1be3e:us-central1:miampa-prueba2
[END app_yaml]
App Engine和CloudSQL实例位于同一区域:us-central
任何帮助都会很棒。谢谢。
答案 0 :(得分:2)
我找到了解决方法:
我的datasources.json:
{
"db": {
"name": "db",
"connector": "memory"
},
"appAmpa": {
"name": "appAmpa",
"connector": "mysql",
"socketPath": "/cloudsql/miampa-1be3e:us-central1:miampa-prueba2",
"database": "prueba",
"user": "root",
"password": "XXXXXXX"
}
}
和我的app.yaml
[START app_yaml]
runtime: nodejs
env: flex
beta_settings:
cloud_sql_instances: miampa-1be3e:us-central1:miampa-prueba2
[END app_yaml]
谢谢。
答案 1 :(得分:0)
您可能想按google cloud SQL手册(https://cloud.google.com/sql/docs/mysql/sql-proxy)中所述检查Google Cloud SQL代理方法。 datasources.json中的host参数无效,因此无法连接。