Cool SQL Snippets
To send output of MySQL query to CSV directly.
Have you ever had a client ask for a decent data dump from a database that they can view in excel?
Here is a quick way to have the output from a MySQL query directly to a file formatted as a CSV file:
SELECT col_1,col_2,col_3 FROM table INTO OUTFILE '/tmp/file_name.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'