MySQL query to CSV
mysql dbname -uuser -ppassword -h "host" -e 'query' | sed "s/'/\'/;s/\t/\",\"/g;s/^/\"/;s/$/\"/;s/\n//g" > file.csv