Я установил felixge/node-mysql
через npm (npm install mysql
), и теперь я хочу подключиться к базе данных mysql, но каждый раз, когда я пытаюсь подключиться, возникает эта ошибка:
{ [Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect' }
undefined
мой источник nodejs:
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);
});
Но я могу легко получить доступ к своей базе данных MySQL через командную строку:
[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>
Кто-нибудь может мне помочь, в чем моя ошибка?