首页 > 解决方案 > Sequelize - 错误:getaddrinfo ENOTFOUND(在一个非常好的地址上)

问题描述

我正在尝试将使用AngularExpress/Sequelize制作的网站投入生产,但总是有 Sequelize 错误:

HostNotFoundError [SequelizeHostNotFoundError]: getaddrinfo ENOTFOUND dodobwtdodob.mysql.db
    at ConnectionManager.connect (C:\Users\Dorian\Desktop\Développement Web\Mes sites\capitales\server\node_modules\sequelize\lib\dialects\mysql\connection-manager.js:120:17)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at async ConnectionManager._connect (C:\Users\Dorian\Desktop\Développement Web\Mes sites\capitales\server\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:318:24)
    at async C:\Users\Dorian\Desktop\Développement Web\Mes sites\capitales\server\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:250:32
    at async ConnectionManager.getConnection (C:\Users\Dorian\Desktop\Développement Web\Mes sites\capitales\server\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:280:7)
    at async C:\Users\Dorian\Desktop\Développement Web\Mes sites\capitales\server\node_modules\sequelize\lib\sequelize.js:613:26        
    at async MySQLQueryInterface.createTable (C:\Users\Dorian\Desktop\Développement Web\Mes sites\capitales\server\node_modules\sequelize\lib\dialects\abstract\query-interface.js:225:12)
    at async Function.sync (C:\Users\Dorian\Desktop\Développement Web\Mes sites\capitales\server\node_modules\sequelize\lib\model.js:1300:5)
    at async Sequelize.sync (C:\Users\Dorian\Desktop\Développement Web\Mes sites\capitales\server\node_modules\sequelize\lib\sequelize.js:793:35) {
  parent: Error: getaddrinfo ENOTFOUND dodobwtdodob.mysql.db
      at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:69:26) {
    errno: -3008,
    code: 'ENOTFOUND',
    syscall: 'getaddrinfo',
    hostname: 'dodobwtdodob.mysql.db',
    fatal: true
  },
  original: Error: getaddrinfo ENOTFOUND dodobwtdodob.mysql.db
      at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:69:26) {
    errno: -3008,
    code: 'ENOTFOUND',
    syscall: 'getaddrinfo',
    hostname: 'dodobwtdodob.mysql.db',
    fatal: true
  }
}

我不明白,因为我一直使用相同的配置,例如,当我在其他项目上使用 PHP PDO 对象时它工作正常。它在我的 OVH VPS 上也不起作用,我收到连接被拒绝错误(即使我必须查看网上的所有教程),但这是另一个问题。

这是我的db.config.js

module.exports = {
    HOST: "dodobwtdodob.mysql.db",
    USER: "dodobwtdodob",
    PASSWORD: "secretpassword",
    DB: "dodobwtdodob",
    dialect: "mysql",
    pool: {
      max: 5,
      min: 0,
      acquire: 30000,
      idle: 10000
    },
    port:3306
  };

这里是我的index.js的一部分:

const dbConfig = require("../config/db.config.js");

const Sequelize = require("sequelize");
const sequelize = new Sequelize(dbConfig.DB, dbConfig.USER, dbConfig.PASSWORD, {
  host: dbConfig.HOST,
  dialect: dbConfig.dialect,
  port: dbConfig.port,
  pool: {
    max: dbConfig.pool.max,
    min: dbConfig.pool.min,
    acquire: dbConfig.pool.acquire,
    idle: dbConfig.pool.idle
  }
});

标签: javascriptnode.jsexpresssequelize.js

解决方案


请将主机名“dodobwtdodob.mysql.db”更改为 ipAddress(主机地址)。


推荐阅读