MySQL to CSV

This sections will contains code regarding different PHP & MySQL features and contains help about php/mysql issues.

MySQL to CSV

Postby Web Guru on April 8th, 2008, 12:34 pm

This quick and handy command line in mysql> will allow you to dump your mysql table to an external csv file.

Code: Select all
mysql> SELECT [your database];

mysql> SELECT * INTO OUTFILE '/tmp/result.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM [table];


If all goes well, you will see result.csv in your /tmp directory. You can of course, open the csv file in MS Excel

Important note: The part after ENCLOSED BY is a single quote (’), followed by a double quote (”), then a single quote (’) again and NOT two double quotes.
User avatar
Web Guru
 
Posts: 66
Joined: March 24th, 2008, 7:59 am
Location: Lahore, Pakistan

Return to PHP / MySQL / XML

Who is online

Users browsing this forum: No registered users and 0 guests

cron