title: Pool connection for Multiple Mysql Database in Node.js
body: <p>I am trying to create a multi tenant node.js application (with also sub domains) where each user has their own database under a single host, (say an rds instance).</p>
  
  <p>So it will be easier for me to handover the database to that particular user to access that particular database.</p>
  
  <p>So my problem here is when an user request the api, is it possible to dynamically change the database name based on the request.</p>
  
  <p>One thing that popped up in my mind is to create a pool connection with  credentials that have access to all database and add the database name in the query, in this way i can achieve what i want, but just out of curiosity is it possible to add the database name after the connection pool has been created, without adding it to the query.</p>
  
  <p>My solution : </p>
  
  <pre><code>select * from 'dbname'.users
  </code></pre>
  
  <p>What i am looking for: </p>
  
  <pre><code>const pool = mysql.createPool({
      host: process.env.DB_HOST,
      user: process.env.DB_USERNAME,
      password: process.env.DB_PASSWORD,
      // database: process.env.DB_NAME, leaving out since db name should be dynamic
      connectionLimit: 5,
      supportBigNumbers: true,
  });
  </code></pre>
  
  <p>And in middleware when i need db access, i should be able to set the db name based on the request. </p>
  
  <p>The reason behind this is, I have created the application and wrote the queries without the database name, now i should add the logic to every query in my application.</p>