I've written about how you can use mysqldump to output specific records before but what if you need to export data from a complex query for a one off report:

SELECT lastName, firstName, count(*)
FROM User
INNER JOIN User_Log on User.id = User_Log.UserId
GROUP BY lastName, firstName;

In order to export this to a CSV file you can tack the following on to the end of you're query and it will be exported:

INTO OUTFILE '/tmp/data.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';

Then you just need to download the file and send it to your client.