Categories
express mysql node.js

has exceeded the ‘max_user_connections’ resource

I have a MySQL, Express, Angular, NodeJS application and sometimes when I log in I get the following error in my node console:

TypeError: Cannot read property ‘query’ of undefined

The error occurs in my passport.local.js file, this is the line:

connection.query('SELECT * FROM users WHERE username LIKE ?', [username], function (err, user) {

This is the passport function

passport.use(new LocalStrategy(
function(username, password, done) {
console.log('app.js');
pool.getConnection(function(err, connection) {
console.log('err: ' + err);
console.log(connection);
connection.query('SELECT * FROM users WHERE username LIKE ?', [username], function (err, user) {
if (err) throw err;
for (var i = user.length - 1; i >= 0; i--) {
var current = user[i];
}
if(current){
if(bcrypt.compareSync(password, current.password)){
return done(null, user);
} else {
return done(null, false);
}
} else {
console.log('no user');
return done(null, false);
}
});
connection.release();
});
}
));

I require my pool in the top of my file

var pool = require('../../config/connection');

When the error occurs the:

console.log(connection);  

Gets:

undefined

I also log the error:

console.log('err: ' + err);

Shows:

 err: Error: ER_USER_LIMIT_REACHED: User 'bfe4a8980ede74' has exceeded the 'max_user_connections' resource (current value: 10)