Darren Beale Web developer & early adopter

mysqldump to CSV file


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]

By bealers
Darren Beale Web developer & early adopter