我有一个节点服务器,它创建一个到mysql的连接池,如果在一段时间内没有活动连接被服务器关闭,并且进一步访问会引发错误。不知道该去哪里,研究过一些运气不大的论坛。
var mysql = require('mysql');
var connection = require('express-myconnection');
// DB connection
var dbOptions = {
host: 'localhost',
user: 'admin',
password: 'admin',
port: 3306,
database: 'data',
multipleStatements: true,
connectionLimit: 20
};
app.use(connection(mysql, dbOptions, pool));
错误
Whoops there is an uncaught error Error: Connection lost: The server closed the connection.
at Protocol.end (/opt/www/CMI_intern_2/node_modules/mysql/lib/protocol/Protocol.js:109:13)
at Socket.<anonymous> (/opt/www/CMI_intern_2/node_modules/mysql/lib/Connection.js:109:28)
at emitNone (events.js:72:20)
at Socket.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:921:12)
at nextTickCallbackWith2Args (node.js:442:9)
at process._tickCallback (node.js:356:17)
答案 0 :(得分:0)
连接池工作正常,一些旧代码中存在隐藏的数据库连接,这是根本原因。没问题。
答案 1 :(得分:0)
实际上,如果有人在调用localhost添加数据库选项时遇到这些错误 socketPath:'/ var / run / mysqld / mysqld.sock' 解决这个问题