title: mysql to CSV with column names on first row inserted dynamically
body: <p>I'm revising my original question significantly...  </p>
  
  <p>This works perfectly for dumping your table to a CSV with the field names on the first row.</p>
  
  <pre><code>SELECT 'field1', 'field2', 'field3' 
  UNION SELECT * INTO OUTFILE '/var/tmp/table_name.csv' 
  FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' 
  LINES TERMINATED BY '\n' FROM table_name;
  </code></pre>
  
  <p>However, when you have hundreds of fields and new fields are added or fields are changed or deleted from time to time I need something dynamic that will put the field names in the format above dynamically so this query will work in a script anytime without having to manually update the field names by hand.</p>