现在有个项目,用mysql连接池打开了链接,在执行完sql完没有关闭,造成mysql服务中基本都是处于sleep的连接数,请问mysql node如何关闭连接池的链接?
7 回复
用的这个吗?:https://github.com/felixge/node-mysql/
文档上面有些:
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'me',
password : 'secret'
});
connection.connect();
connection.query('SELECT 1 + 1 AS solution', function(err, rows, fields) {
if (err) throw err;
console.log('The solution is: ', rows[0].solution);
});
connection.end();
@songqinghehe 不是很清楚,然后看到连接池是这样子关闭的:
pool.end(function (err) {
// all connections in the pool have ended
});
@youqingkui 摘抄了一段代码: pool.getConnection(function (err, conn) { if (err) console.log("POOL ==> " + err);
conn.query(selectSQL,function(err,rows){
if (err) console.log(err);
console.log("SELECT ==> ");
for (var i in rows) {
console.log(rows[i]);
}
conn.release();
});
}); 在执行sql完毕后执行conn.release()来释放的链接?