问题1:node中mysql连接池的connectionLimit指什么,它和mysql的最小连接数和最大连接数的关系是什么
问题2:mysql max_connections是什么,max_used_connections是什么,两者的关系?为啥max_connecitons可以小于max_used_connections?
问题3:mysql pool.on('connection',callback)在什么情况下触发?例如我的这段代码,什么时候触发connection事件?
var mysql = require('mysql');
var http = require('http');
var pool = mysql.createPool({
host : 'localhost',
user : 'guest',
password : '****',
database : 'test',
connectionLimit: 2
});
pool.on('acquire', function(connection){
console.log('connection %d accuired', connection.threadId);
});
pool.on('connection', function (connection) {
connection.query('SET SESSION auto_increment_increment=1')
});
pool.on('enqueue', function () {
console.log('Waiting for available connection slot');
});
// pool.end(function (err) {
// console.log('end!')
// });
http.createServer(function(req,res){
if(req.url==='/url1') {
pool.getConnection(function(err, connection) {
connection.query('select * from teacher', function(error,results,fields) {
if (error) throw error;
res.end(JSON.stringify(results));
// connection.release();
});
})
}
if(req.url==='/url2') {
pool.getConnection(function(err, connection) {
connection.query('select * from student', function(error,results,fields) {
if (error) throw error;
res.end(JSON.stringify(results));
connection.release();
});
})
}
}).listen(8001);
守着星空守着你
相关分类