Don't you hate disclaimers? I do, but before I do anything else, I must ask that you don't use the techniques below unless you are emailing responsibly.
Today I needed to pull email addresses for people who had signed up to a thing out of MySQL and into MailChimp so that I could actually email them about the thing. MySQL actually has a very cute feature for exporting the results of an SQL query as a CSV file, which I had to look up to remember how to do it. It goes something like this:
My original query*
select u.username, u.email, a.account_name from users u inner join accounts a on a.user_id = u.id where a.status_id = 2;
To write this to a file, we use MySQL's SELECT ... INTO
OUTFILE
feature, so my query suddenly looks like this:
select u.username, u.email, a.account_name into outfile '/tmp/users-extract.csv' from users u inner join …[Read more]