得到错误“连接ECONNREFUSED 127.0.0.1:3306";在连接到MySQL时 [英] Getting error "connect ECONNREFUSED 127.0.0.1:3306" while connecting to mysql

查看:1084
本文介绍了得到错误“连接ECONNREFUSED 127.0.0.1:3306";在连接到MySQL时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是nodeJ的新手,正在尝试开发我的第一个应用程序.我通过npm安装了mysql软件包,它已安装,并且可以在package.json中看到它的成功条目.但是,当我尝试连接到mysql服务器时,它给了我这个错误connect ECONNREFUSED 127.0.0.1:3306.我在StackOverflow上搜索了此问题,并通过将条目socketPath: '/var/run/mysqld/mysqld.sock'添加到配置对象来使其他具有相同问题的用户运行该问题.但是,当我将其添加到配置对象中时,出现了新的错误connect ENOENT /var/run/mysqld/mysqld.sock.

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;

我正在使用Windows计算机,并且之前已通过XAMPP软件包安装了mysql.这可能是连接失败的原因吗?

I'm using a Windows machine and had mysql installed before via XAMPP package. Can this be the reason behind the connection failure?

推荐答案

您是否已启动XAMPP服务器?.

Have you started your XAMPP Server ?.

连接ECONNREFUSED 127.0.0.1:3306-当您不启动XAMPP服务器时,就会出现此错误.

connect ECONNREFUSED 127.0.0.1:3306 -- this error came, when you not started your XAMPP server.

请删除socketPath&尝试一次.

Please remove socketPath & try once.

当我没有启动XAMPP服务器时,我也遇到了类似的问题.

I have faced same kind of issue, when I not started the XAMPP server.

这篇关于得到错误“连接ECONNREFUSED 127.0.0.1:3306";在连接到MySQL时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆