title: Too many Connections on Node-MySQL
body: <p>I get Error <code>Too many connections</code> when there to much items in a loop with INSERT IGNORE INTO.</p>
  
  <pre><code>function insertCases(cases) {
      for(var i in cases) {
          var thequery = 'INSERT IGNORE INTO `cases` SET keysused='+cases.keysused+' 
          pool.query(thequery, function(ee, rr) {
              if(ee) {
                  logger.info(ee);
                  throw ee;
              }
          });
      }
  }
  </code></pre>
  
  <p>When there are now 100+ cases so 100 times INSERT IGNORE INTO than I get too many connections. I don't know how much exactly crash it but with 100 it's working.</p>
  
  <p>What I read is, that query runs the query and also closes the connection after done, so I read, I don't need to close it after than.</p>
  
  <p>If I run 100, waiting short time and run 100 again and so on, it don't get Too many connections error. </p>
  
  <p>It's only when there runs so much time at once.</p>
  
  <p>That's my DB settings</p>
  
  <pre><code>var db_config = {
      connectionLimit : 5000,
      host: 'localhost',
      user: 'userexample',
      password: '*******',
      database: 'example.com'
  };
  </code></pre>
  
  <p>and that's the function that createPool.</p>
  
  <pre><code>function database_connection() {
  pool = mysql.createPool(db_config);
  pool.getConnection(function(err, connection) {
      if(err) {
          logger.error('[ERROR] Connecting to database "' + err.toString() + '"');
          setTimeout(function() { database_connection(); }, 2500);
      }
      else
      {
          pool.query('SET NAMES utf8');
          pool.query('SET CHARACTER SET utf8');
          logger.trace('[INFO] Connected to database and set utf8!');
      }
  });
  </code></pre>
  
  <p>}</p>
  
  <p>All queries on the node are simply run with <code>pool.query</code></p>
  
  <p>The <code>database_connection()</code> is called on start of the node</p>