Search code examples
mysqlnode.jsgoogle-app-engine

ENOENT when connecting to Google Cloud SQL from App Engine


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
}

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

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.


Solution

  • Check your logs for any errors during startup using:

    1. the following cmd gcloud app logs tail -s default or,

    2. with the log viewer https://console.cloud.google.com/logs/viewer

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