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);
});
7条答案
按热度按时间ozxc1zmp1#
I have removed port option and issue is resolved.
8mmmxcuj2#
Problem solved i was using port : 3307 in phpMyadmin instead of 3306
lymgl2op3#
Add
socketPath
in the dialect optionsExample code snippet:
t0ybt7op4#
FIX for Node.js use:
It looks as though the current version of sequelize (7) only works on Node.js versions
^12.22.0
,^14.17.0
&^16.0.0
.www.sequelize.org
says that some other versions may work as well.Use NVM to install and switch to version 16.0.0:
If you don't already have node version manager you can install it with
Then install version 16 with
nvm i 16.0.0
and then tell your application to use it withnvm use 16.0.0
.jv4diomz5#
If you're running XAMMP server on windows, first start apache server with MySQL
You get this error probably because your server is not running.
check your server and restart if necessary.
xwbd5t1u6#
Just restart the mysql server.
Linux and Mac:
service mysql restart
Windows:
Open the Run window by using the Windows+R keyboard. Second, type services.msc and press Enter: Find mysql and restart the service.
bxfogqkk7#
**the solution is just only Start Your Xampp Apache and MySQL Service.
**