I have the following code. I’m using XAMPP to run a local MySQL database, but I can’t connect to it using sequelize.
import { Sequelize } from "sequelize";
const user_auth_db = new Sequelize('db_name', 'root', '', {
host: 'localhost',
dialect: 'mysql',
port: "3306",
});
try {
await user_auth_db.authenticate();
console.log("Connection has been established succesfully");
} catch (error) {
console.log("Unable to connect to db", error);
}
The error is the following:
parent: Error: connect ECONNREFUSED 127.0.0.1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3306,
fatal: true
},
I tried changing the port, password and user and try it that way but it didn’t work.