title: Bash script to dump mysql view into csv
body: <p>I am trying to dump an output from from a MYSQL view into a CSV using a bash script.</p>
  
  <p>As inspiration I used this post: <a href="https://stackoverflow.com/questions/9026709/how-to-use-a-bash-script-to-write-to-a-mysql-table">How to use a bash script to write to a mysql table</a></p>
  
  <p>The strange part is that SELECT column1,column2,column3 FROM syntax works fine, but it is not practical when you have some 15 columns...</p>
  
  <p>Also SELECT count(*) FROM works</p>
  
  <p>However SELECT * FROM  is throwing a MYSQL syntax error</p>
  
  <pre><code>#!/bin/bash
  
  fpath=/tmp/
  fname=`date +%Y%m%d-%H%M%S`.csv
  savedest=\'$fpath$fname\'
  
  echo "Saving into"$savedest
  
  params="-u root -p mydb"
   s1="SELECT * FROM flat_view INTO OUTFILE "
  s2=" FIELDS TERMINATED BY ','"
  s3=" ENCLOSED BY '\"'"
  s4=" LINES TERMINATED BY '\\n'"
  selectend=";"
  
  echo $s1$savedest$s2$s3$s4$selectend | mysql $params
  </code></pre>
  
  <p>I am thinking I have not escaped something properly.</p>
  
  <p>PS. This is Centos 5.8 and mysql  Ver 14.12 Distrib 5.0.95</p>