I have the following code, which I am trying to run. I have given comments accordingly to mention what all I have tried.
// 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;
});
Since the default port is not changed, the phpMyAdmin is working fine for me. But I am not able to connect using node-mysql driver from Node.js.
The following is the error message I am getting:
amolkulkarni@ubuntu:~/Project/Node_MySQL$ node app.js
{ [Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
fatal: true }
Could anyone please help on this?
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
I am able to connect to mysql using mysql -hlocalhost -uroot -ppassword
but if I replace with ip e.g. mysql -h192.168.1.10 -uroot -ppassword
It gives error as follows:
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.3.78' (111)
Your server is started with --skip-networking flag:
Do not listen for TCP/IP connections at all. All interaction with mysqld must be made using named pipes or shared memory (on Windows) or Unix socket files (on Unix). This option is highly recommended for systems where only local clients are permitted.
Try to connect to unix socket or start server with TCP enabled.