Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

connect ECONNREFUSED - node js , sql

Tags:

node.js

mysql

I have the next code in a js file:

var mysql = require('mysql');
var TEST_DATABASE = 'nodejs_mysql_test';
var TEST_TABLE = 'test';
var client = mysql.createClient({
  user: 'root',
  password: 'root',
});

client.query('CREATE DATABASE '+TEST_DATABASE, function(err) {
  if (err && err.number != mysql.ERROR_DB_CREATE_EXISTS) {
    throw err;
  }
});

But I get this error:

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
          ^
Error: connect ECONNREFUSED
    at errnoException (net.js:632:11)
    at Object.afterConnect [as oncomplete] (net.js:623:18)

As I understand it, this is a connection problem - but how do I solve it?

( I'm working on windows 7)

Thanks!!

like image 777
kakush Avatar asked Jan 11 '12 19:01

kakush


1 Answers

I know two ways to solve it:

  1. In mysql.conf, comment skip-networking.

  2. Try to set the socket like this:

    var client = mysql.createClient({
    user: uuuu,
    password: pppp,
    host: '127.0.0.1',
    port: '3306',
    _socket: '/var/run/mysqld/mysqld.sock',});
    
like image 105
limon Avatar answered Oct 10 '22 21:10

limon