mysqljs / mysql

A pure node.js JavaScript Client implementing the MySQL protocol.
MIT License
18.21k stars 2.53k forks source link

Windows firewall gives "connect EACCES" Error #858

Closed ken92 closed 10 years ago

ken92 commented 10 years ago

I've copied the sample code for connecting to the MySQL database into a .js file (making modifications to connect to my server, of course) and it gives this error (with the paths edited for brevity):

    Error: connect ENOENT
    at errnoException (net.js:901:11)
    at Object.afterConnect [as oncomplete] (net.js:892:19)
    --------------------
    at Protocol._enqueue (C:\...\test\node_modules\mysql\lib\protocol\Protocol.js:110:48)
    at Protocol.handshake (C:\...\test\node_modules\mysql\lib\protocol\Protocol.js:42:41)
    at Connection.connect (C:\...\test\node_modules\mysql\lib\Connection.js:101:18)
    at repl:1:13
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.EventEmitter.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)
    at Interface._ttyWrite (readline.js:760:14)

Here's the code:

var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : 'hostname',
  user     : 'user',
  password : 'password',
  socketPath : '/var/lib/mysql/mysql.sock'
});
connection.connect();
connection.query('SELECT 1 + 1 AS solution', function(err, rows, fields) {
  if (err) throw err;
  console.log('The solution is: ', rows[0].solution);
});
connection.end();

The socketPath was found by running "locate mysql | grep .sock" Also, I'm running the code on a Windows machine while the database is on Linux. I'm not sure if that makes a difference, but there you go.

I've been Googling this all day and haven't made any headway, so if anyone could point me in the right direction, I'd really appreciate it.

dougwilson commented 10 years ago

Remove socketPath; you only use that to connect using a UNIX socket on the same machine.

ken92 commented 10 years ago

When I remove socketPath, I get this error:

Error: connect EACCES
    at errnoException (net.js:901:11)
    at Object.afterConnect [as oncomplete] (net.js:892:19)
    --------------------
    at Protocol._enqueue (C:\Users\Eridan\Desktop\CEMS-test\node_modules\mysql\lib\protocol\Protocol.js:110:48)
    at Protocol.handshake (C:\Users\Eridan\Desktop\CEMS-test\node_modules\mysql\lib\protocol\Protocol.js:42:41)
    at Connection.connect (C:\Users\Eridan\Desktop\CEMS-test\node_modules\mysql\lib\Connection.js:101:18)
    at Object.<anonymous> (C:\Users\Eridan\Desktop\CEMS-test\test.js:9:12)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)

What does this error mean?

dougwilson commented 10 years ago

It means your Windows firewall blocked the outgoing TCP connection.

dougwilson commented 10 years ago

Try running your node script in an elevated (Administrator) command prompt to see if it helps.

ken92 commented 10 years ago

Allowing Node-Webkit through my firewall fixed it. Thanks!