简体   繁体   English

启动我的 node.js 应用程序时出现错误 connect ECONNREFUSED 127.0.0.1:3306

[英]Get error connect ECONNREFUSED 127.0.0.1:3306 when start my node.js app

When I start my node.js app I get this error:当我启动 node.js 应用程序时,出现此错误:

SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306

What I was doing:我在做什么:

 - create a user:
CREATE USER 'main'@'localhost' IDENTIFIED BY 'myPass';

 - give this user all privileges
GRANT ALL PRIVILEGES ON *.* TO 'main'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;

I then try to connect through my code on production and it gives me an error: connect ECONNREFUSED 127.0.0.1:3306.然后我尝试通过我的生产代码进行连接,它给了我一个错误:connect ECONNREFUSED 127.0.0.1:3306。

But in my localhost environment it connects well.但在我的本地主机环境中,它连接良好。 And when I try to connect to DB using command line on VPS it works too: mysql -umain -p当我尝试在 VPS 上使用命令行连接到数据库时,它也可以工作: mysql -umain -p

I can't connect with code.我无法与代码连接。 But on my localhost it connects.但是在我的本地主机上它连接。 Double checked my loggin and pass for DB user in .env.仔细检查了我的登录信息并通过 .env 中的 DB 用户。

尝试重新启动 MySQL 服务。

I found a problem!我发现了一个问题! In my mysql config file (etc/my.cnf) was bind-address = my VPS ip So, when I remove this line it starts to listen al ips.在我的 mysql 配置文件(etc/my.cnf)中, bind-address = my VPS ip所以,当我删除这一行时,它开始监听 al ips。

Thanks every one!谢谢大家!

Just in case you fall into my category, I simply forgot to put on my local server (XAMMP).以防万一你属于我的类别,我只是忘了把我的本地服务器 (XAMMP) 放在上面。 You might want to check if your MySQL server is active.您可能想要检查您的 MySQL 服务器是否处于活动状态。

I had the same problem and solved it by adding "socketPath" to my sequelize deceleration like this:我遇到了同样的问题,并通过在我的 sequelize 减速中添加“socketPath”来解决它,如下所示:

const sequelize = new Sequelize('db-name', 'user', 'password', {
  host: 'localhost',
  dialect: 'mysql',
  dialectOptions: {
    socketPath: 'your socket path',
    supportBigNumbers: true,
    bigNumberStrings: true
  },
});

find your socket path by entering /etc/mysql/mysqld.cnf: then you have their your socket path:通过输入 /etc/mysql/mysqld.cnf 找到你的套接字路径:然后你有你的套接字路径:

user        = mysql
# pid-file  = /var/run/mysqld/mysqld.pid
# socket    = /var/run/mysqld/mysqld.sock
# port      = 3306
# datadir   = /var/lib/mysql

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 部署 NODE.JS + MONGODB(CRUD APP)时在 HEROKU 上连接 ECONNREFUSED 127.0.0.1:3000 - connect ECONNREFUSED 127.0.0.1:3000 on HEROKU when deploying NODE.JS + MONGODB (CRUD APP) 节点app.js返回错误:连接ECONNREFUSED 127.0.0.1:27017 - Node app.js returns Error: connect ECONNREFUSED 127.0.0.1:27017 在节点 js 中连接 ECONNREFUSED 127.0.0.1:21 错误 - connect ECONNREFUSED 127.0.0.1:21 error in node js [SequelizeConnectionRefusedError]:连接ECONNREFUSED 127.0.0.1:3306 - [SequelizeConnectionRefusedError]: connect ECONNREFUSED 127.0.0.1:3306 节点+ MySQL [ECONNREFUSED 127.0.0.1:3306] - Node + MySQL [ECONNREFUSED 127.0.0.1:3306] Redis 在 Windows 10 上使用 Node.JS 一直失败:错误:Redis 连接到 127.0.01.1:637279.D 失败 - 0.0.01.1:63727.0 连接失败。 - Redis keeps failing on Windows 10 with Node.JS : Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379 错误:在node.js中连接ECONNREFUSED-数据库 - Error: connect ECONNREFUSED in node.js - database Gulp / Node.js错误:连接ECONNREFUSED - Gulp / Node.js error: connect ECONNREFUSED Node.js 错误:连接 ECONNREFUSED - Node.js Error: connect ECONNREFUSED 未处理的拒绝 SequelizeConnectionRefusedError:连接 ECONNREFUSED 127.0.0.1:3306 - Unhandled rejection SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM