node.js mysql error: ECONNREFUSED

For some very odd reason, my computer only allowed me to have port 3306 as default port for my connection in order for it to work.

Screenshot


Overview

For anyone else having this problem and is running mamp. I suspected the problem had to do with the network and not MySQL or Node.js.

Solution

If you open MAMP and click MySQL in the left navigation panel it will pull up the MySQL options page. In the center of the page you will see a checkbox that says,

"Allow network access to MySQL".

Check this box and then restart your MAMP. At this point you can now test your connection to MySQL with telnet or a node.js script.

Hint

Remember you can check which port your MySQL is running on by opening MAMP and clicking the ports link on the left navigation panel.

Visual Aid

enter image description here


If this has worked before, my first guess would be that you've already got a copy of your node.js script running in the background which is holding the connection.

I believe connection refused is a tcp/ip error message, rather than something from MySQL which suggests that it is either not running or is running on another port or with sockets.

Could you try telnet'ing to port 3308? To see if the server is running on that port?

telnet localhost 3308

Can you also try:

mysql -hlocalhost -uroot -pxxx

I know this question has been answered, but for me the problem was that the mysql server listens on a Unix socket not on a tcp socket. So the solution was to add:

port: '/var/run/mysqld/mysqld.sock'

to the connection options.

Tags:

Mysql

Node.Js