Last Updated: February 25, 2016
·
3.052K
· julianduque

Export MySQL query into a CSV file

Sometimes we need and easy way to export data from MySQL to a CSV format, with the following query you can do it directly!

SELECT * INTO OUTFILE '/tmp/export.csv' FIELDS TERMINATED BY ','      
OPTIONALLY ENCLOSED BY '"' ESCAPED BY ‘\\’ 
LINES TERMINATED BY '\n'
FROM customers WHERE 1