clarkk clarkk - 1 year ago 457
MySQL Question

node.js mysql error: ECONNREFUSED

Why can't I connect to the mysql server?

On the same server an Apache/PHP server is running and it connects without problems!?

var mysql_link = {
host : 'localhost',
port : 3308,
database: 'nodetest',
user : 'root',
password : 'xxx'

var connection = mysql.createConnection(mysql_link);

if(err != null){
response.write('Error connecting to mysql:' + err+'\n');



{ [Error: connect ECONNREFUSED]
syscall: 'connect',
fatal: true }


root@dyntest-amd-6000-8gb /var/www/node/dyntest # ps ax | grep mysqld
7928 pts/0 S+ 0:00 grep mysqld
28942 ? S 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/run/mysqld/
29800 ? Sl 17:31 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/var/lib/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/lib/mysql/mysql-error.log --open-files-limit=65535 --pid-file=/var/run/mysqld/ --socket=/var/run/mysqld/mysqld.sock --port=3306

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download