Friday, December 16, 2011

MySQL Query to CSV

Here is the quick and dirty on how to query directly to a csv in MySQL. 
SELECT id, name, email INTO OUTFILE '/tmp/result.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY ‘\\’
LINES TERMINATED BY '\n'
FROM users WHERE 1
In MS Windows OUTFILE would be:
OUTFILE 'C:/tmp/results.csv'
Make sure mysql can write to the location of your outfile

No comments:

Post a Comment