我有以下代码,我正在尝试运行。我已经给出了相应的评论,以提及我所做的一切。
// File saved as app.js
var mysql = require('mysql');
var connection = mysql.createConnection({
host:'localhost', //even tried with 127.0.0.1
port:3306, //confirmed port by looking into /etc/mysql/my.cnf has [client] port = 3306
user:'root', //credentials are verified since Php My Admin logs in with same
password:'password' //credentials are verified since Php My Admin logs in with same
//Even tried to connect using _socket: '/var/run/mysqld/mysqld.sock'
});
connection.connect(function(err) {
// connected! (unless `err` is set)
if(err)
console.log(err); return;
});
由于默认端口未更改,因此 phpMyAdmin 对我来说工作正常。但我无法使用来自Node.js的 node-mysql 驱动程序进行连接。
以下是我收到的错误消息:
amolkulkarni@ubuntu:~/Project/Node_MySQL$ node app.js
{ [Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
fatal: true }
有人可以帮忙吗?
更新:根据评论
amolkulkarni@ubuntu:~/ ps ax | grep mysqld
5905 ? S 0:00 sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking
5906 ? Sl 0:12 /usr/sbin/mysqld --skip-grant-tables --skip-networking
28964 ? Ssl 0:00 /usr/sbin/mysqld
29098 pts/3 S+ 0:00 grep --color=auto mysqld
我可以使用连接到 mysql,mysql -hlocalhost -uroot -ppassword
但是如果我用 ip 替换,例如mysql -h192.168.1.10 -uroot -ppassword
它会给出如下错误:
错误 2003 (HY000): 无法连接到“192.168.3.78”上的 MySQL 服务器 (111)