title: How can I execute a MySQL statement generated from information_schema automatically?
body: <p>I have a MySQL server with many databases that have a similar table structure. When a piece of legacy software goes into an error state it writes a line to a few tables as well as emailing me. I am trying to write a simple SQL query to clear these tables down (<code>TRUNCATE</code>).</p>
  
  <p>In my bash script I currently have:</p>
  
  <pre><code>mysql -e "SELECT CONCAT('TRUNCATE TABLE ', TABLE_SCHEMA, '.', TABLE_NAME, ';') 
            FROM information_schema.TABLES 
            WHERE TABLE_NAME IN ('errorLog', 'errorLogBacktrace', 'errorLogUrl');" | 
  grep -v 'CONCAT(' |
  mysql
  </code></pre>
  
  <p>Line returns added to help with legibility hopefully.</p>
  
  <p>But this does not appear to work and only executes the first <code>TRUNCATE TABLE</code> query generated by the above select.</p>
  
  <p>The output from the select portion of the above code:</p>
  
  <pre><code>mysql -e "SELECT CONCAT('TRUNCATE TABLE ', TABLE_SCHEMA, '.', TABLE_NAME, ';') 
            FROM information_schema.TABLES 
            WHERE TABLE_NAME IN ('errorLog', 'errorLogBacktrace', 'errorLogUrl');" | 
  grep -v 'CONCAT('
  </code></pre>
  
  <p>is:</p>
  
  <pre><code>TRUNCATE TABLE db1.errorLog;
  TRUNCATE TABLE db1.errorLogBacktrace;
  TRUNCATE TABLE db1.errorLogUrl;
  TRUNCATE TABLE db2.errorLog;
  TRUNCATE TABLE db2.errorLogBacktrace;
  TRUNCATE TABLE db2.errorLogUrl;
  TRUNCATE TABLE db3.errorLog;
  TRUNCATE TABLE db3.errorLogBacktrace;
  TRUNCATE TABLE db3.errorLogUrl;
  </code></pre>
  
  <p>How can I get this to work? Do I need to loop over the lines and execute them one by one, if so how?</p>