在节点js中,我创建了一个用于数据库连接的池
var pool = mysql.createPool( // use a pool for multiple connections
{
connectionLimit : 4,
waitForConnections : true,
queueLimit : 0,
host : hostName,
user : userName,
password : passName,
database : databaseName
});
进行四次连接后,代码运行正常。 但是在五个连接请求在池中排队以进行连接之后,我以
的身份发出连接请求pool.getConnection(funtion(err){
if(err)
console.log('[error] with connection'+err);
});
然后发生错误--->
[error] with connection Error: ER_USER_LIMIT_REACHED: User 'b1312146aa0cc6' has
exceeded the 'max_user_connections' resource (current value: 4)
答案 0 :(得分:0)
试试这个:
var mysql = require('mysql');
var pool = mysql.createPool({
connectionLimit: 4,
waitForConnections: true,
queueLimit: 0,
host: hostName,
user: userName,
password: passName,
database: databaseName
});
var sql = 'select * from bag where id = ?';
var args = [1]
pool.query(sql, args, function(err, result) {
console.log('result:', result);
})
pool.query(sql, args, function(err, result) {
console.log('result:', result);
})
pool.query(sql, args, function(err, result) {
console.log('result:', result);
})
pool.query(sql, args, function(err, result) {
console.log('result:', result);
})
pool.query(sql, args, function(err, result) {
console.log('result:', result);
})
// ...