If you’re SSH’d into a MySQL server and want to export MySQL query results to CSV (readable by Excel), simply add the below snippet to the end of your query.
INTO OUTFILE '/tmp/results.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'
Note that ‘/tmp/results.csv’ in the code above should correspond to a writeable destination, and the file can’t already exist.