How to Export a Large MySQL Table on MAMP to a CSV File

You many need to export a data base table that is larger than phpMyAdmin’s maximum allowed size (in the export table tab). An easy way to do this by using the terminal.
I have provided a simple example below for MAMP users like me. This information is based on a blog post I found on how to export mysql data to a csv file I hope this makes someone’s day a little easier.

/Applications/MAMP/Library/bin/mysql -u username -ppassword NameOfDatabase -B -e "SELECT * FROM tablename;" >  '/path/to/file.csv'

The above code creates a TAB delimited file. You may want to use grep to convert the tabs to ;(semi colons).
I use semi-colons because there are often commas within the actual data.
Remember that in whatever text editor you are using to make sure it is using UNIX line returns.

Leave a Reply

Your email address will not be published. Required fields are marked *