RSS

mysqldump to CSV file

Thu, Feb 17, 2005

System Administration

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]

This post was written by:

Bealers - who has written 350 posts on Darren Beale.


Contact the author

1 Comments For This Post

  1. Chris Sainsbury Says:

    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 777 or the command will fail!

Leave a Reply