NodeJS Sequelize - 启动应用程序时出错

时间:2017-02-23 13:55:30

标签: node.js sequelize.js

当我尝试启动节点应用程序时出现以下错误:

Unhandled rejection SequelizeConnectionError: Connection lost: The server closed the connection.
    at Handshake._callback (/Users/move/Vagrant/apps/appcampinas/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:95:20)
    at Handshake.Sequence.end (/Users/move/Vagrant/apps/appcampinas/node_modules/mysql/lib/protocol/sequences/Sequence.js:86:24)
    at /Users/move/Vagrant/apps/appcampinas/node_modules/mysql/lib/protocol/Protocol.js:399:18
    at Array.forEach (native)
    at /Users/move/Vagrant/apps/appcampinas/node_modules/mysql/lib/protocol/Protocol.js:398:13
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)

之前有没有人见过这个错误?

谢谢!

1 个答案:

答案 0 :(得分:0)

Sequelize不支持自动重新连接,因此如果您的应用程序空闲,连接可能会被丢弃。

处理此问题的首选方法是使用连接池。

{
  "development": {
    "username": "root",
    "password": "root",
    "database": "app_development",
    "host": "127.0.0.1",
    "dialect": "mysql",
    "pool": {
      "maxConnections": 100,
      "maxIdleTime": 1000
    },
    "define": {
      "underscored": true,
      "freezeTableName": true,
      "paranoid": true,
      "charset": "utf8"
    }
  }
}