How do I fix the timeout error on the connection between Node app and Mysql?

Posted April 29, 2020 8.4k views
DigitalOcean Managed MySQL Database

I am new to deployment. I have created a node droplet which I access successfully with Putty and also a database cluster, which in the mysql workbench works fine, also when I connect it with the code in development so locally works just fine. The problem is that when I access the droplet, clone the project, after npm install and npm start to test it shows me timeout error from the database:

Error: connect ETIMEDOUT
    at Connection._handleTimeoutError (/root/gmd-server/node_modules/mysql2/lib/connection.js:178:17)
    at ontimeout (timers.js:482:11)
    at tryOnTimeout (timers.js:317:5)
    at Timer.listOnTimeout (timers.js:277:5)

I hope I was clear.
How can I fix it?
Thanks in advance.

edited by bobbyiliev

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 @majkellveizaj,

This sounds like a firewall problem, I could suggest a few things:

  • If you have added trusted sources for your cluster, make sure to allow your Droplet’s IP address as well

  • If you are using a firewall on your Droplet like UFW for example, make sure to open the Managed Database port for outgoing TCP connections from your Droplet

Let me know how it goes!