Labels

Showing posts with label mysql. Show all posts
Showing posts with label mysql. Show all posts

Monday, May 19, 2014

Export data from MySQL to CSV

I cannot believe I am still using MySQL, after I fell in love with PostgreSQL, but many systems I manage still use MySQL and will stay like that. Today I needed to export data to CSV and I didn't remember how, well this is it.

mysql> SELECT * INTO OUTFILE '/tmp/registro_semanario.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY ‘\\’ LINES TERMINATED BY '\n' FROM registro_semanario ORDER BY e_mail;

Taken from this site: https://ariejan.net/2008/11/27/export-csv-directly-from-mysql/ but it has an error with single quotes.

Added in the cheat sheet to remember.