Getting error “connect ECONNREFUSED 127.0.0.1:3306” while connecting to mysql

匿名 (未验证) 提交于 2019-12-03 02:33:02

问题:

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?

回答1:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!