I'm new to nodeJs and trying to develop my first application. I installed mysql package through npm, It got installed and I can see a successful entry of it in package.json. However, when I'm trying to connect to mysql server, it gives me this error connect ECONNREFUSED 127.0.0.1:3306
. I searched for this issue on StackOverflow and the other users who had the very same issue got it running by adding an entry socketPath: '/var/run/mysqld/mysqld.sock'
to the configuration object. But when I added this to my configuration object, I got a new error connect ENOENT /var/run/mysqld/mysqld.sock
.
Here's the code by which I'm trying to connect to the server
var express = require('express'); var router = express.Router(); var mysql = require('mysql'); var connection = mysql.createConnection({ host: 'localhost', user: 'root', password: '', database: 'blog', socketPath: '/var/run/mysqld/mysqld.sock' }); connection.connect(); module.exports = router;
I'm using a Windows machine and had mysql installed before via XAMPP package. Can this be the reason behind the connection failure?