Craig Newlander wrote:
> Hello,
> How can I execute query and have it's output (just data, no structure)
> saved to a CSV file?
> Thanks,
>From the command line? AFAIK mysql will only output tab separated results
so you have to do something like:
echo "SELECT 'a', 'b', 1" |mysql db |perl -ne 'chomp; print join(",", map {
m/\D/ ? qq("$_") : $_ } split/\t/)."\n"' > yourfile.csv
This is a bit simplistic, e.g. it will not handle columns that have quotes
in the result, etc..
Also, don't forget the first line returned contains the column names.
--Bill
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php