search

Home  >  Q&A  >  body text

"ECONNRESET" error in Node.js MySQL application

This error comes from my hosted node mysql application. Works fine on my local machine

node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: read ECONNRESET
    at TCP.onStreamRead (node:internal/stream_base_commons:217:20)
Emitted 'error' event on Connection instance at:
    at Connection._handleProtocolError (/home/ufkgmlcg/nodevenv/happyface_social/16/lib/node_modules/mysql/lib/Connection.js:423:8)
    at Protocol.emit (node:events:513:28)
    at Protocol._delegateError (/home/ufkgmlcg/nodevenv/happyface_social/16/lib/node_modules/mysql/lib/protocol/Protocol.js:398:10)
    at Protocol.handleNetworkError (/home/ufkgmlcg/nodevenv/happyface_social/16/lib/node_modules/mysql/lib/protocol/Protocol.js:371:10)
    at Connection._handleNetworkError (/home/ufkgmlcg/nodevenv/happyface_social/16/lib/node_modules/mysql/lib/Connection.js:418:18)
    at Socket.emit (node:events:513:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -104,
  code: 'ECONNRESET',
  syscall: 'read',
  fatal: true
}

how to solve this problem?

P粉201448898P粉201448898340 days ago571

reply all(1)I'll reply

  • P粉986028039

    P粉9860280392023-12-27 09:08:37

    It's hard to tell without knowing the details of where the application is hosted, and the code snippet used to connect to mysql.

    However, it is very likely that in the code that connects to mysql, you add the path to the localhost where mysql is running, and when you host the application, the path to the mysql database is different.

    To resolve this issue, you should read How to connect to mysql on the platform where your application is hosted, and then use environment variables to connect to it.

    You will use environment variables to specify the local database path on your computer, and also specify the managed database path in the hosting platform.

    reply
    0
  • Cancelreply