title: Running the same query on multiple databases in one query (MySQL)
body: <p>I have multiple databases with the same structure but different unrelated names, and I want to run this query on all of them:</p>
  
  <pre><code>SELECT FROM &lt;dbname&gt;.`cms_users` WHERE `email` LIKE '%admin.something%'
  </code></pre>
  
  <p>I searched a bit in the information_schema and found a table called <code>SCHEMATA</code> that contains the databases' names which is ultimately what I need to run the query above and I can do so manually by just replacing the database name myself and creating the query. However I want to do it automatically using <a href="http://dev.mysql.com/doc/refman/5.0/en/loop.html" rel="nofollow">a mysql loop</a> but I'm not very certain how can I do this and how can I concatenate the database name to the query and run it.</p>
  
  <p>My pseudo code for this would be as follows:</p>
  
  <pre><code>array dbnames= select `SCHEMA_NAME` from `information_schema`.`SCHEMATA`;
  
  loop start on dbnames
  SELECT FROM dbnames[index].`cms_users` WHERE `email` LIKE '%admin.bilsi%';
  loop end
  </code></pre>
  
  <p>Any help to put this or a better logic into mysql syntax? Thanks.</p>