When I start my node.js app I get this error:
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.
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
I can't connect with code. But on my localhost it connects. Double checked my loggin and pass for DB user in .env.
ECONNREFUSED means no process is listening at the given address and port.
Once you have MySQL up and running on your computer, you can access it by using Node. js. To access a MySQL database with Node. js, you need a MySQL driver.
The error ECONNREFUSED 127.0.0.1:3306 is being raised by Node.js itself, and not this module. This module passes the error through, though, from Node.js. Basically, this module is asking Node.js to create a TCP connection to 127.0.0.1 , port 3306 , but for whatever reason, Node.js cannot do this and raises the ECONNREFUSED error.
Here it's my success story with incredible persistant Node.js error connect ECONNREFUSED . Day 1. I run this code, and should work fine. Usual errors, maybe 3-4 minutes. I changed host: 'localhost' to host : '127.0.0.1', port: 8080, or maybe 8000, oh yes, 3306 this is.
In this case, the process will be the one with the pid 7668. To kill it and restart the server, run kill -9 7668. Show activity on this post. Check with starting mysql in terminal. Use below command Show activity on this post. ECONNREFUSED error means that connection could not be made with the target service (in your case localhost:8080 ).
The Unhandled 'error' event is referring not providing a function to the request to pass errors. Without this event the node process ends with the error instead of failing gracefully and providing actual feedback. You can set the event just before the request.write line to catch any issues: Show activity on this post.
Try restarting the MySQL service.
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.
Thanks every one!
I had the same problem and solved it by adding "socketPath" to my sequelize deceleration like this:
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:
user = mysql
# pid-file = /var/run/mysqld/mysqld.pid
# socket = /var/run/mysqld/mysqld.sock
# port = 3306
# datadir = /var/lib/mysql
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