This is a weird problem and I\'m not sure what\'s going on. I installed MySQL on a linux box I have running Ubuntu 10.04 LTS. I can access mysql via SSH mysql -p
In my.cnf, I changed bind-address to 0.0.0.0 and now connections from my node app are correctly accepted.
As the first and good answer says, MySQL isn't listening to your local TCP/IP sockets.
Connect your mysql.Client
module using:
client.port = '/tmp/mysql.sock';
and fill in wherever your mysql socket file is located. If you can't find this, consider using this heavy but success-guaranteed system-wide search
cd / ; find * | grep mysql.sock
Manually defining the socket fixed this problem for me.
var client = mysql.createClient({
user: '(your user here)',
password: '(your password here)',
host: '127.0.0.1',
port: '3306',
_socket: '/var/run/mysqld/mysqld.sock',
});
I have had similar issues, but with MongoDB. I think you need to make your host
point to 127.0.0.1
rather than localhost
.
Check:
$ nslookup localhost
and
$ nslookup localhost.
both should return an address of 127.0.0.1
Also check cat /etc/hosts
if localhost maps to ipv6: ::1 localhost
then change to 127.0.0.1 localhost
localhost
might be pointing to the ipv6 address rather than the ipv4 address.
Hope this helps :)
For me, this problem occurred on an Ubuntu box only accessible on our internal net (though I think this solution applies regardless of the network). I was able to access mysql perfectly well with mysql Workshop and with Node.js mysql plugin from my dev system but not from Node running on the server.
In particular, I tried localhost, 127.0.0.1 or even 'serverName', which was defined as 127... in /etc/hosts. I got nothing but ECONNREFUSED.
Turns out that my mysql instance was set to only accept connections addressed to the server's IP address. That is, it would only accept connections from
{host:'172.xxx.xxx.xxx', user:'blah', ....
Good luck!!