我无法使用 express js 应用程序将 gcloud mysql 与 App Engine 连接

I can't connect gcloud mysql with app engine using express js application

我正在尝试将我的 express js 应用程序部署到应用程序引擎,我还想 link 这个应用程序引擎到 mysql 数据库,但是在连接到数据库时出现此错误:

Error: connect ENOENT /cloudsql/********3li      at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1145:16)
2021-10-15 08:46:41 appengineedokanapi[20211015t103941]      --------------------
2021-10-15 08:46:41 appengineedokanapi[20211015t103941]      at Protocol._enqueue (/app/node_modules/mysql/lib/protocol/Protocol.js:144:48)
2021-10-15 08:46:41 appengineedokanapi[20211015t103941]      at Protocol.handshake (/app/node_modules/mysql/lib/protocol/Protocol.js:51:23)
2021-10-15 08:46:41 appengineedokanapi[20211015t103941]      at PoolConnection.connect (/app/node_modules/mysql/lib/Connection.js:116:18)
2021-10-15 08:46:41 appengineedokanapi[20211015t103941]      at Pool.getConnection (/app/node_modules/mysql/lib/Pool.js:48:16)
2021-10-15 08:46:41 appengineedokanapi[20211015t103941]      at Pool.query (/app/node_modules/mysql/lib/Pool.js:202:8)
2021-10-15 08:46:41 appengineedokanapi[20211015t103941]      at /app/api/routes/users.js:48:22
2021-10-15 08:46:41 appengineedokanapi[20211015t103941]      at processTicksAndRejections (internal/process/task_queues.js:97:5) {
2021-10-15 08:46:41 appengineedokanapi[20211015t103941]    errno: 'ENOENT',
2021-10-15 08:46:41 appengineedokanapi[20211015t103941]    code: 'ENOENT',
2021-10-15 08:46:41 appengineedokanapi[20211015t103941]    syscall: 'connect',
2021-10-15 08:46:41 appengineedokanapi[20211015t103941]    address: '/cloudsql/********3li ',
2021-10-15 08:46:41 appengineedokanapi[20211015t103941]    fatal: true
2021-10-15 08:46:41 appengineedokanapi[20211015t103941]  }

我也在使用 node-mysql 库和 express js

const pool = mysql.createPool({
    user: process.env.DB_USER,
    password: process.env.DB_PASSWORD,
    database: process.env.DB_DATABASE,
    socketPath: `/cloudsql/${process.env.INSTANCE_CONNECTION_NAME}`,
})

app.yaml 包含:

env_variables: 
  INSTANCE_CONNECTION_NAME : ********3li
  DB_DATABASE : databaseName
  DB_USER : databaseUser
  DB_PASSWORD : *******

正如 'blacknamefornow' 在评论中指出并由 mohamed-ali 确认的那样,问题出在 app.yaml 文件中的 INSTANCE_CONNECTION_NAME env 变量中。

参考this回答,格式应该是{project-id}:europe-west1:{database}.