Sequelize 的 Mysql 连接超时

标签 mysql node.js sequelize.js

我在使用 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);
    });

enter image description here

最佳答案

通常 MySQL 在端口 3306 上工作(您正在端口 3307 上执行请求)。 对于另一种方式,您可以尝试使用 MySQL 包: https://github.com/mysqljs/mysql .

致以诚挚的问候。

关于Sequelize 的 Mysql 连接超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55040030/

相关文章:

javascript - 无法读取未定义的属性 'sync'

MySql 完全连接(联合)并在多个日期列上排序

php - 管理用户警告

mysql - 显着增加 varchar 字段的长度是否会影响性能?

javascript - 将 Electron 打包到现有 App 中

javascript - 如何将 nodemon 与 .env 文件一起使用?

mysql - Rails 将应用程序与用户自己的外部数据库连接起来

javascript - 如何让JS先等待前面几行代码完成?

node.js - Sequelize 移动类方法到单个文件

javascript - 调用sequelize findAll方法后setDataValue不是函数