Node.js Sequelize 和 MySQL 出现 ETIMEDOUT 错误

问题描述 投票:0回答:1

我遵循了本教程: https://bezkoder.com/node-js-express-sequelize-mysql/

我的代码是相同的,只是我使用的端口发生了变化,但尽管如此,我还是出现了以下错误:

Server is running on port 3000.
(node:22880) UnhandledPromiseRejectionWarning: SequelizeConnectionError: connect ETIMEDOUT
    at ConnectionManager.connect (C:\Users\rutig\OneDrive\Desktop\node\node_modules\sequelize\lib\dialects\mysql\connection-manager.js:126:17)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async ConnectionManager._connect (C:\Users\rutig\OneDrive\Desktop\node\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:318:24)
    at async C:\Users\rutig\OneDrive\Desktop\node\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:250:32
    at async ConnectionManager.getConnection (C:\Users\rutig\OneDrive\Desktop\node\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:280:7)
    at async C:\Users\rutig\OneDrive\Desktop\node\node_modules\sequelize\lib\sequelize.js:613:26
    at async MySQLQueryInterface.createTable (C:\Users\rutig\OneDrive\Desktop\node\node_modules\sequelize\lib\dialects\abstract\query-interface.js:225:12)
    at async Function.sync (C:\Users\rutig\OneDrive\Desktop\node\node_modules\sequelize\lib\model.js:1300:5)
    at async Sequelize.sync (C:\Users\rutig\OneDrive\Desktop\node\node_modules\sequelize\lib\sequelize.js:793:35)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:22880) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:22880) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

我不明白为什么完全相同的文件对其他人有效,但对我无效。

mysql node.js express sequelize.js
1个回答
0
投票

试试这个代码:

dialectOptions: {
  connectTimeout: 60000
}
© www.soinside.com 2019 - 2024. All rights reserved.