Unable to connect Node.JS to MySql on same ubuntu machine. Timeout error/ConnectionRefused.

I have written a Node.Js Application for demo purpose to connect to DB. I ma new to DO platform and connecting remote servers. The Node.Js application that I have written, I am able to connect to MySQL DB (present/using Managed DB Cluster provided by DO.) The logic is same, connection string details different. But, that same Node.Js application is unable to establish a connection to the MySQL present on the same ubuntu machine. I have taken a LEMP stack on Ubuntu. On, the LEMP stack ubuntu machine. I have PhpMyAdmin also which is working fine. In addition to LEMP, I have Node installed on the same Ubuntu Virtual Machine. This Node.Js application is unable to establish a connection to the MySQL which is a part of LEMP on this Ubuntu machine. But, the node.js application is able to establish connection to MySQL Managed DB Cluster.

Submit an answer
Answer a question...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Bobby Iliev
Site Moderator
Site Moderator badge
February 24, 2022


If you are connecting to the local MySQL installation, you need to try the following:

  • Change the database host from the server IP to so that the Node.js service would connect to the MySQL service locally rather then via the public interface
  • Make sure that the MySQL service is running:
systemctl status mysql

If this is still not working, can you share the exact error that you are getting and also the connection string that you are using? Make sure to remove any sensitive information before sharing the connection string here.