我正在使用node.js并面临node崩溃的问题。错误消息如下所示。
Error: Connection lost: The server closed the connection.
at Protocol.end (/var/www/versions/project/js/node_modules/mysql/lib/protocol/Protocol.js:78:13)
at Socket.<anonymous> (/var/www/versions/project/js/node_modules/mysql/lib/Connection.js:81:28)
at Socket.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:919:16
at process._tickCallback (node.js:419:13)
我在 Node 服务器中使用mysql查询..但是在崩溃时它没有任何操作... Node 在不同的时间段自动崩溃。
最佳答案
我发现使用连接池仅在需要时获取连接是最好的方法。
// do this once
var pool = mysql.createPool( opts );
// then, just before you need a connection do this
pool.getConnection(function(err, connection) {
if (err) throw err;
// use the connection
// don't forget to release the connection when you are done...
connection.release();
});
关于php - Node.js在没有任何操作的情况下被mysql自动崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25358894/