node-mysql pool如何关闭?
var mysql = require(‘mysql’); var pool = mysql.createPool(…);
pool.getConnection(function(err, connection) { // Use the connection connection.query( ‘SELECT something FROM sometable’, function(err, rows) { // And done with the connection. connection.release();
// Don't use the connection here, it has been returned to the pool.
}); });
release只是单纯的将当前connection释放当pool中,否则如果请求的客户端多了,那数据库压力是不是很大?希望懂的人指点一下。
2 回复
放回连接池内的连接,在空闲一段时间后会被关闭回收的,空闲时间长度可以配置,注意看文档和源代码
thx.