Question

Cannot connect to database with node.js

Posted December 15, 2020 5.8k views
MySQLNode.jsDigitalOceanDeployment

Urgent need please help me out with the issue I am getting the below error when trying to connect my node.js with database

I am getting the below error when trying to connect my node.js with database, its working fine with the local database but when connecting to digital ocean database getting the below error can anyone please help me out..

Unable to connect to the database: ConnectionError [SequelizeConnectionError]: connect ETIMEDOUT
    at ConnectionManager.connect (C:\Users\Gorthy\Desktop\log-reader\log-reader\node_modules\sequelize\lib\dialects\mysql\connection-manager.js:126:17)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  parent: Error: connect ETIMEDOUT
      at Connection._handleTimeoutError (C:\Users\Gorthy\Desktop\log-reader\log-reader\node_modules\mysql2\lib\connection.js:178:17)
      at listOnTimeout (internal/timers.js:549:17)
      at processTimers (internal/timers.js:492:7) {
    errorno: 'ETIMEDOUT',
    code: 'ETIMEDOUT',
    syscall: 'connect',
    fatal: true
  },
  original: Error: connect ETIMEDOUT
      at Connection._handleTimeoutError (C:\Users\Gorthy\Desktop\log-reader\log-reader\node_modules\mysql2\lib\connection.js:178:17)
      at listOnTimeout (internal/timers.js:549:17)
      at processTimers (internal/timers.js:492:7) {
    errorno: 'ETIMEDOUT',
    code: 'ETIMEDOUT',
    syscall: 'connect',
    fatal: true
  }
}
(node:13788) UnhandledPromiseRejectionWarning: SequelizeConnectionError: connect ETIMEDOUT
    at ConnectionManager.connect (C:\Users\Gorthy\Desktop\log-reader\log-reader\node_modules\sequelize\lib\dialects\mysql\connection-manager.js:126:17)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:13788) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)        
(node:13788) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
edited by MattIPv4

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hi there @qnptechnologies,

Are you using a DigitalOcean Managed Database cluster or did you install an SQL server on a Droplet?

If you are using a Managed Database, I would suggest making sure that you are using the correct custom Port and also that you’ve added your IP address to the trusted list so that you could connect to the database.

If you are using an SQL server installed on a Droplet, then make sure that you’ve allowed external connections as described here:

https://www.digitalocean.com/community/tutorials/how-to-allow-remote-access-to-mysql

Hope that this helps!
Regards,
Bobby

by Mark Drake
Many websites and applications start off with their web server and database backend hosted on the same machine. With time, though, a setup like this can become cumbersome and difficult to scale. A common solution is to separate these functions by setting up a remote database, allowing the server...