mysql - 在 mysql 数据库池中请求连接时达到用户限制

标签 mysql node.js database-connection pool

在 Node 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)

最佳答案

试试这个:

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);
})

// ...

关于mysql - 在 mysql 数据库池中请求连接时达到用户限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26424131/

相关文章:

mysql - 如何从mysql表中获取前一天的记录?

node.js - Heroku ENOENT : no such file or directory due to faulty express. js 路由

c# - SQL连接字符串错误: Unable to connect to any of the specified MySQL hosts

c# - Entity Framework 无法删除数据库,正在使用的数据库

mysql - 什么更好,许多重复的行或增加表格?

php - 使用 PHP 在 60 秒后自动将行插入 MySQL

php - Laravel 将 `id` 更改为 `AUTO_INCREMENT`

node.js - bcrypt 与 nodejs 比较

javascript - 覆盖console.log(或一般的任何函数): Is there a proper way to do this?

c# - 找不到远程主机 "."错误