1. Tool
Toad for MySQL, free software
2. Solution A
Toad's default behavior is exporting the whole table, thus we'd better create a temporary table first, insert the query result, and follow the Export Wizard, beware choose the SQL Script option.
3. Solution B