How to export MySQL table as CSV

Exporting data from MySQL to CSV is a common need and is often needed to either reimport the data or process it externally using programatically. Let’s see how to export contents of a table in CSV format

Option 1: Using PHPMyAdmin

If you have phpmyadmin installed you can use the export feature available and us the csv format

Option 2: From command line

Here is the syntax to export table

select * into outfile "/tmp/mytable.csv" fields enclosed by '"' terminated by ',' from myschema.mytable limit 100000

limit is optional, you can remove if you don’t want to specify the number of records

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.