CNode

node-mysql pool如何关闭?

Ttechbirds发布于12 年前最后回复12 年前2 回复4605 浏览0 收藏

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)

Y
yeaha#1·12 年前

放回连接池内的连接,在空闲一段时间后会被关闭回收的,空闲时间长度可以配置,注意看文档和源代码

参与回复
登录后即可参与回复。登录