[英]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.