mysql 模块,报了一下错误,有很好的、优雅的解决方法吗?
26|node_pr | at Object.<anonymous> (/home/vanilla/www/node_server/node_monkey_proxy/app.js:19:22)
26|node_pr | Trace: fatal error: Connection lost: The server closed the connection.
26|node_pr | at Protocol.clientObj._protocol._delegateError (/home/vanilla/www/node_server/node_monkey_proxy/models/mysql.js:52:21)
26|node_pr | at Protocol.end (/home/vanilla/www/node_server/node_monkey_proxy/node_modules/mysql/lib/protocol/Protocol.js:113:8)
26|node_pr | at Socket.<anonymous> (/home/vanilla/www/node_server/node_monkey_proxy/node_modules/mysql/lib/Connection.js:115:28)
26|node_pr | at emitNone (events.js:91:20)
26|node_pr | at Socket.emit (events.js:185:7)
26|node_pr | at endReadableNT (_stream_readable.js:975:12)
26|node_pr | at _combinedTickCallback (internal/process/next_tick.js:74:11)
26|node_pr | at process._tickDomainCallback (internal/process/next_tick.js:122:9)
6 回复
监听error事件
@carlisliu 监听了
clientObj.on('error', function(err) {
console.log('db error', err);
if (err.code === 'PROTOCOL_CONNECTION_LOST') {
mysqlInstance = new Mysql();
} else {
throw err;
}
});
````
并卵
sequlize
一直报错还是mysql的8小时限制?
@DevinXian 过段时间就会连接报错,几天
链接已经断开了,应该用连接池,设置好链接闲置时间 ,我采用 generic-pool 来完美解决这个问题 当然, node-mysql也有内置的连接池
ejsexcel excel模板引擎