Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

felixge/node-mysql coudn't connect to database

felixge/node-mysql coudn't connect to database

Problem

I installed the felixge/node-mysql via npm (npm install mysql), and now i want to connect to the mysql database, but every time I try to connect this error happens:

{ [Error: connect ECONNREFUSED]
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect' }
undefined

my nodejs source:

var mysql = require("mysql")
var db = mysql.createClient({
    host:"localhost",
    user:"root",
    password:"root"
});

db.query("SELECT 1",function(err,result,fields){
    if(err) {
        console.log(err);
    }
    console.log(result);
});

But i can easily access to my MySQL database via command line:

[[email protected]] $ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.18-log Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SELECT 1
    -> ;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)

mysql> 

Can anybody help me what is my mistake?

Problem courtesy of: Gergely Fehérvári

Solution

I had to modify the mysql configuration file. I commented out skip-networking and it fixed my problem.

If anybody can explain me why is that good I would thank it.

Solution courtesy of: Gergely Fehérvári

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

felixge/node-mysql coudn't connect to database

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×