Node.js经常关闭与MySQL的连接。这每2-4小时间隔发生一次。我该如何阻止这种情况发生?
{ Error: Connection lost: The server closed the connection.
at Protocol.end (/home/zubizi/retech_node/node_modules/mysql/lib/protocol/Protocol.js:112:13)
at Socket.<anonymous> (/home/zubizi/retech_node/node_modules/mysql/lib/Connection.js:97:28)
at Socket.<anonymous> (/home/zubizi/retech_node/node_modules/mysql/lib/Connection.js:502:10)
at Socket.emit (events.js:187:15)
at endReadableNT (_stream_readable.js:1085:12)
at args.(anonymous function) (/home/zubizi/.nvm/versions/node/v11.2.0/lib/node_modules/pm2/node_modules/event-loop-inspector/index.js:138:29)
at process._tickCallback (internal/process/next_tick.js:63:19) fatal: true, code: 'PROTOCOL_CONNECTION_LOST' }
我使用了Node JS mysql database disconnect这个解决方案,但仍然无法查询MySql。
我使用以下代码使连接保持活动状态:
// keep connection alive
setInterval(function () {
conn.query('SELECT 1');
console.log('Keep alive the connection.');
}, 30000);
但这并没有影响任何事情。