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:
[user@host] $ 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
Related Articles
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.