我正在使用Sequelize作为我的Node.js应用程序和MySQL数据库的ORM。在遵循一些教程之后,我添加了连接MySQL到Node的代码,但在输入npm start命令后,我得到了以下错误信息:
无法连接到数据库:{ 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);
});