MySQL Query Results as CSVs

Here’s a simple example showing how to export the results of a MySQL query to a CSV file on disk:

SELECT some,fields,to,export
INTO OUTFILE '/tmp/sqlresult.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'
FROM some_table WHERE some_other_field=123;

Hopefully that’s reasonably self-explanatory. Obviously you’ll edit the SQL accordingly and replace /tmp/sqlresult.csv with the path to the file you want to create.

Tags:

Leave a Reply