Skip to content

Always ECONNREFUSED #704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jerodev opened this issue Jan 11, 2014 · 7 comments
Closed

Always ECONNREFUSED #704

jerodev opened this issue Jan 11, 2014 · 7 comments

Comments

@jerodev
Copy link

jerodev commented Jan 11, 2014

Hi,

I am using this in combination with sockets to read messages and put them in the database. But somehow it won't connect to the database. I am 100% sure the connection details are correct. But every time I run the script I get the following output:

We have liftoff!
{ [Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
fatal: true }

This is the script I use:
var mysql = require("mysql");
var connection = mysql.createConnection({
host: 'localhost',
user: '',
password: '',
database: ''
});

var WebSocket = require('ws')
  , ws = new WebSocket('ws://ws.myvps.be:8553');

console.log("We have liftoff!");

ws.on('open', function() {
        connection.connect(function(e){
                console.log(e);

                if (!e){
                        ws.send('{"op":"get_messages"}');
                        console.log("Start!");
                }

        });
});
@sidorares
Copy link
Member

Are you sure your local mysql server listens on tcp/localhost? Could you try to connect with command line client:

> mysql -h 127.0.0.1

@jerodev
Copy link
Author

jerodev commented Jan 12, 2014

Yes, this works perfectly.
I did add the -u and -p ofcourse, but I removed them in the code sample.

@sidorares
Copy link
Member

try to connect with debug: true option. Also, what is your mysql server version?

@dougwilson
Copy link
Member

@jerodev just to make sure we are all on the same page, you did in fact include -h 127.0.0.1 in your mysql command, right? Not including -h or using -h localhost is actually very different from -h 127.0.0.1, unfortunately. If it works leaving out -h or using -h localhost but does not work when using -h 127.0.0.1 this means your MySQL server does not have networking enabled and is not actually listening on a TCP port. You can then use socketPath to connect over the socket file instead.

@jerodev
Copy link
Author

jerodev commented Jan 12, 2014

Thanks for all the help!

I have tried using localhost and 127.0.0.1 and both worked with the mysql command but not with node.
To test the connection I created a php page that inserts a row in this database with these credentials on localhost and it worked fine.

Could you tell me how to use the socketPath option?

@sidorares
Copy link
Member

var mysql = require("mysql");
var connection = mysql.createConnection({
  socketPath: '/var/lib/mysql/mysql.sock',
  user: '',
  password: '',
  database: ''
});

Make sure that you are using same socket path as your server use ( you can get it with mysql_config --socket command)

@jerodev
Copy link
Author

jerodev commented Jan 12, 2014

I installed libmysqlclient-dev and used the socket to connect to the database. The script is now running fine.

Thank you! :)

@jerodev jerodev closed this as completed Jan 12, 2014
dveeden pushed a commit to dveeden/mysql that referenced this issue Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants