has exceeded the 'max_user_connections' resource
<p>I have a MySQL, Express, Angular, NodeJS application and sometimes when I log in I get the following error in my node console:</p>

<blockquote>
  <p>TypeError: Cannot read property 'query' of undefined</p>
</blockquote>

<p>The error occurs in my <code>passport.local.js</code> file, this is the line:</p>

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

<p>This is the passport function</p>

<pre><code>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 &gt;= 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();
        });
    }
));
</code></pre>

<p>I require my <code>pool</code> in the top of my file</p>

<pre><code>var pool = require('../../config/connection');
</code></pre>

<p>When the error occurs the:</p>

<pre><code>console.log(connection);  
</code></pre>

<p>Gets:</p>

<blockquote>
  <p>undefined</p>
</blockquote>

<p>I also log the error:</p>

<pre><code>console.log('err: ' + err);
</code></pre>

<p>Shows: </p>

<pre><code> err: Error: ER_USER_LIMIT_REACHED: User 'bfe4a8980ede74' has exceeded the 'max_user_connections' resource (current value: 10)
</code></pre>