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?
Have you started your XAMPP Server ?.
connect ECONNREFUSED 127.0.0.1:3306 -- this error came, when you not started your XAMPP server.
Please remove socketPath & try once.
I have faced same kind of issue, when I not started the XAMPP server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With