title: Node MySQL Connection Pool - wait for database to start
body: <p>How do I check if a MySQL database is ready for some queries from a Node MySQL Connection Pool?</p>
  
  <p>I have a Docker environment consisting of thee containers:</p>
  
  <ul>
  <li>container 1: web server</li>
  <li>container 2: api</li>
  <li>container 3: database</li>
  </ul>
  
  <p>The database container runs a MySQL database. The api container connects to that database. All three containers are started at the same time. The web server container is up after 0,5s. The api container is up after 2s. The database server is up after 20s.</p>
  
  <p>Currently, the api tries to access the tables of the database before the database is up and running. This leads to errors like <em>connection refused</em>. The following code segment always ends up with the message "Error querying database!" when the MySQL database is not yet up:</p>
  
  <pre><code>const sql: string = 'SELECT * FROM sometable;';
  MySQL.createPool({
      connectionLimit: 10,
      acquireTimeout: 30000,
      waitForConnections: true,
      database: 'mydatabase',
      host: 'localhost',
      multipleStatements: true,
      password: 'mypassword',
      user: 'root',
  }).query(sql, (err, result) =&gt; {
      if (result) {
          console.log('Successfully queried database.');
      } else {
          console.log('Error querying database!');
      }
  });
  </code></pre>
  
  <p>Versions in use:</p>
  
  <pre><code>OS: Ubuntu 19.10
  Node: v13.6.0
  MySQL (Node API): "@types/mysql": "2.15.8" and "mysql": "2.17.1"
  MySQL (Docker Database): mysql:5.7.28
  TypeScript: 3.7.4
  </code></pre>
  
  <p>I would like to check (and wait) the database readiness out of the api, possibly using the Connection Pool I use for queries. Is that possible?</p>