Exporting query results from MySQL


You would like to export some query results from MySQL into a format that can be imported in LibreOffice, OpenOffice or Excel.


Try first with the default export options, as by doing a google search, there are a lot of different options for specifying field delimeters, lines terminated, etc.
So by not specifying any additional options the export is a tab delimited, linefeed-terminated file which should work in most of the programs.
So in order to do that you would need a folder in the MySQL server that should have write access. Usually /tmp should do. Then you can build your query and at the end add the INTO OUTFILE ‘/path’, like:

SELECT one,max(two) max_two,min(three) min_three 
FROM table 
WHERE one=1 
INTO OUTFILE '/tmp/my_query.csv';

You can use any file ending but usually by specifying .csv the program that you will try to open will understand it.