Output a Postgres or MySQL Query to CSV

I find myself needing to output CSV from database queries a lot, and like an Alzheimer’s patient I am constantly forgetting how to do it. Here’s the quick run-down on how you get queries from your database into a CSV file.

Postgres

\f ','
\a
\t
\o /tmp/output.csv
SELECT column_id, column_name FROM table_name;
\o
\q

Continue reading: Output a Postgres or MySQL Query to CSV