我在使用 Nodejs 和 Sequelize 连接 vagrant box 中的 MySql 时遇到问题。
我可以从 Navicat 或 Python、Nodejs 和 Mysql 包连接到 MySql DB。但我无法与 Nodejs 和 Sequelize 建立联系。 小伙伴们,你们有什么想法吗?
const Sequelize = require('sequelize');
const sequelize = new Sequelize('blog', 'root', null, {
host: 'localhost',
dialect: 'mysql',
operatorsAliases: false,
port: 3307,
pool: {
max: 5,
min: 0,
acquire: 40000,
idle: 20000
},
});
sequelize
.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
})
.catch(err => {
console.error('Unable to connect to the database:', err);
});
最佳答案
通常 MySQL 在端口 3306 上工作(您正在端口 3307 上执行请求)。 对于另一种方式,您可以尝试使用 MySQL 包: https://github.com/mysqljs/mysql .
致以诚挚的问候。
关于Sequelize 的 Mysql 连接超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55040030/