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

Time:10-19

I'm trying to deploy my express js application to app engine, Also I want to link this app engine to the mysql database but I get this error when connection to database :

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]  }

I'm also using node-mysql library with 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 contains:

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

CodePudding user response:

As pointed out by 'blacknamefornow' in a comment and confirmed by mohamed-ali, the problem was in the INSTANCE_CONNECTION_NAME env variable in the app.yaml file.

Referenced from this answer, the format should be {project-id}:europe-west1:{database}.

  • Related