Step 1: Create a text file "query.sql" containing your SQL query using the MySQL "INTO OUTFILE" syntax:
SELECT firstname, lastname FROM client ORDER BY lastname INTO OUTFILE '/tmp/clients.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
Step 2: Use the Linux 'cat' command to pipe this query into MySQL:
cat query.sql | mysql -uMyUser MyDB -p
Where MyUser is your database user and MyDB is the name of the database to run the query on.