Possible Duplicate:
How to export / dump a MySql table into a text file including the field names (aka headers or column names)
I use this SQL snippet to dump a table into CSV text files:
SELECT * FROM brand INTO OUTFILE “e:/brand.csv”
FIELDS TERMINATED BY ‘,’ ENCLOSED BY ‘”‘
LINES TERMINATED BY “\n”;
However this approach doesn’t add the column names at the beginning of the CSV file. My question is how to select all the column / field names as well, just like what phpMyAdmin does when you export the table and select “Put fields names in the first row”.
I figured out a way around having to manually enter those names as long as you’re running MySQL 5 or higher. Here it is, written as a bash script for running on a unix command line:
While not the most graceful solution, i’m sure it can be compressed into a single line by someone who knows SQL and/or bash a little better than me…
What it does is:
Good luck, and if you clean it up, post your results!