SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306
10,764
Solution 1
Problem solved i was using port : 3307 in phpMyadmin instead of 3306
Solution 2
Add socketPath
in the dialect options
Example code snippet:
// Option 1: Passing parameters separately
const sequelize = new Sequelize('Education', 'root', '', {
host: '127.0.0.1',
dialect: 'mysql',
dialectOptions: {
socketPath: '/Applications/MAMP/tmp/mysql/mysql.sock'
}
});
Author by
Anas Zayene
Updated on June 15, 2022Comments
-
Anas Zayene almost 2 years
I'm using Sequelize as an ORM to my node js app and Mysql database , after following some tutorials i m adding this code to connect mysql to the node but after taping npm start i m getting this error : Unable to connect to the database: { SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306
const Sequelize = require('sequelize'); // Option 1: Passing parameters separately const sequelize = new Sequelize('Education', 'root','', { host: '127.0.0.1', dialect: 'mysql' } ); //test db sequelize .authenticate() .then(() => { console.log('Connection has been established successfully.'); }) .catch(err => { console.error('Unable to connect to the database:', err); });
-
Evan P over 2 yearsRemoving the port option could work only in your set-up. As the author mentioned afterwards, on their set-up their port was different than the default, and thus was the connection error.