从App Engine连接到Google Cloud SQL时为ENOENT

从App Engine连接到Google Cloud SQL时为ENOENT

问题描述:

我正在尝试在Google App Engine上部署我的Node.js应用程序,并且部署良好,但是由于某种原因它无法连接到Google Cloud SQL.这是它抛出的东西:

I'm trying to deploy my Node.js app on Google App Engine and it deployed fine, but it can't connect to Google Cloud SQL for some reason. Here's what it throws:

Error: connect ENOENT /cloudsql/my-project-id:asia-east1:my-sql-instance

这是我配置连接的方式:

Here's how I configured the connection:

if (process.env.INSTANCE_CONNECTION_NAME) {
     exports.mysqlConfig = {
         user: process.env.GCLOUD_SQL_USERNAME,
         password: process.env.GCLOUD_SQL_PASSWORD,
         socketPath: '/cloudsql/' + process.env.INSTANCE_CONNECTION_NAME
     }
} else {
    // Use settings for localhost
}

我正在使用node-mysql模块连接到数据库.

I'm using node-mysql module to connect to the database.

App Engine和Cloud SQL已经在同一项目中. 我的理论是App Engine和Cloud SQL必须位于相同的项目中,但是我不确定.

The App Engine and Cloud SQL are already in the same project. My theory is that the App Engine and the Cloud SQL has to be in the same project and same region, but I'm not sure.

在启动过程中使用以下方法检查日志中是否有错误:

Check your logs for any errors during startup using:

  1. 以下cmd gcloud app logs tail -s default

使用日志查看器 https://console.cloud.google.com/logs /viewer

可能是您尚未为项目启用Cloud SQL API: https ://console.developers.google.com/apis/api/sqladmin/overview

Chances are that you have not enabled the Cloud SQL API for your project: https://console.developers.google.com/apis/api/sqladmin/overview