Dead simple this one, but not initially obvious. How do you use mysqldump to generate a CSV file of data?
mysqldump –u [username] –fields-terminated-by=, –tab=[DIR TO SAVE TO] –tables [DB NAME] [TABLENAME] > [TABLENAME].txt
This’ll place into the specified directory two files: one a SQL file containing the table definition and the data as a CSV.
If you want you can extend this to enclose each field in quotes, by using the fields-enclosed-by flag.
note: the minusU above actually reads minusminusU. I had to do this as Wordpress was munging the entry. So to confirm: it’s minusu [username]








November 25th, 2005 at 5:11 pm
After a bit of fiddling I got this version of the command to work:
mysqldump -uroot -ppassword –fields-terminated-by=, –tab=directory –tables databasename tablename > tablename.txt
Make sure directory is set to
chmod -R 777or the command will fail!