【发布时间】:2023-04-01 00:09:01
【问题描述】:
在其他 VPS 中,我有一个远程数据库服务,它每天早上 6:00 重新启动。不幸的是,这会导致即时 MySQL 连接关闭。有什么方法可以知道连接是否结束?
喜欢:
connection.isEnd();
我连接到我的数据库而不使用池连接。 例子:
const connection = mysql.createConnection({
host : _this.config.mysql.database.ip,
user : _this.config.mysql.database.username,
password : _this.config.mysql.database.password,
database : _this.config.mysql.database.db
});
connection.connect(function(err) {
if (err) {
console.error('error connecting: ' + err.stack);
return;
}
_this.bdd = connection;
resolve(_this);
});
【问题讨论】:
标签: mysql node.js database-connection