Node.js 在没有任何操作的情况下被 mysql 自动崩溃 [英] Node.js crashing automatically by mysql without any operation in it
本文介绍了Node.js 在没有任何操作的情况下被 mysql 自动崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 node.js 并面临 node 崩溃的问题.错误信息如下所示.
I am working with node.js and facing a problem with crashing of node . Error message shown below.
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)
我在节点服务器中使用 mysql 查询......但在崩溃时它没有对其进行任何操作......节点在不同的时间段内自动崩溃.
I'm using mysql queries in node server..but at crashing time it does not have any operation on it... node crashing automatically different period of time.
推荐答案
我发现使用连接池仅在需要时获取连接是最好的方法.
I have found that working with connection pools to grab a connection only when you need it is the best approach.
// 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();
});
这篇关于Node.js 在没有任何操作的情况下被 mysql 自动崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文