我这里有个问题。。。我希望你能帮助我……
我正在使用Node.js后端和MySQL数据库开发Flutter聊天应用程序。
在开发环境中....一切正常...但在VPS环境中,Node.js代码无法连接MySQL服务,我找不到发生了什么!!....
服务器抛出下一个日志
Unable to connect to the database: { SequelizeConnectionError: connect ETIMEDOUT
at ConnectionManager.connect (/data/Jasper/SERVER_BTN95/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:102:17)
at process._tickCallback (internal/process/next_tick.js:68:7)
name: 'SequelizeConnectionError',
parent:
{ Error: connect ETIMEDOUT
at Connection._handleTimeoutError (/data/Jasper/SERVER_BTN95/node_modules/mysql2/lib/connection.js:189:17)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)
errorno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect',
fatal: true },
original:
{ Error: connect ETIMEDOUT
at Connection._handleTimeoutError (/data/Jasper/SERVER_BTN95/node_modules/mysql2/lib/connection.js:189:17)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)
errorno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect',
fatal: true } }
(node:3270005) UnhandledPromiseRejectionWarning: Error: SequelizeConnectionError: connect ETIMEDOUT
at Server.<anonymous> (/data/Jasper/SERVER_BTN95/models/server.js:58:23)
at Generator.throw (<anonymous>)
at rejected (/data/Jasper/SERVER_BTN95/models/server.js:6:65)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:3270005) 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(). (rejection id: 1)
(node:3270005) [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.
这是我的连接代码
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const sequelize_1 = require("sequelize");
const db = new sequelize_1.Sequelize('cw', 'root', 'mypass', {
dialect: 'mysql',
host: '/*I put here my VPS IP but I don’t know if I have to put 10.0.0.2 or localhost*/',
port: my_port,
multipleStatements : true
});
db.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
})
.catch((err) => {
console.log('Unable to connect to the database:', err);
});
process.on('unhandledRejection', function(err) {
console.log(err);
// sendInTheCalvary(err);
});
exports.default = db;
说真的我希望你能帮我...因为我有这个问题有一段时间...我来这里是因为我不知道还能做什么....还有....对不起我的英语....我会说西班牙语!!
我试过加法
const promise1 = new Promise(function(resolve, reject) {
throw new Error('Promise 1 has tanked.');
});
const promise2 = new Promise(function(resolve, reject) {
promise1.then();
});
(async function() {
try {
await promise2;
} catch(err) {
console.log(err);
}
})();
我的代码但发生了什么事
1条答案
按热度按时间jm2pwxwz1#
我想明白了这是我的错误,我是用错误的端口连接到MySQL服务器时。我使用的是项目(开发环境)中的端口,这是默认的MySQL 3306端口。