mysql provides an easy mechanism for writing the results of a select statement into a text file on the server. using extended options of theinto outfilenomenclature, it is possible to create a comma separated value (csv) which can be imported into a spreadsheet application such as openoffice or excel or any other applciation which accepts data in csv format.
in your terminal
given a query such ass
select * from pet;
which returns all columns of data, the results can be placed into the file /tmp/pet.txt using the query:
select * from pet
into outfile ‘/tmp/pet.txt’
this will create a tab-separated file, each row on its own line. to alter this behavior, it is possible to add modifiers to the query:
select * from pet
into outfile ‘/tmp/pet.csv’
fields terminated by ‘,’
lines terminated by ‘/n’
in this example,the fields will be separated by commas, and each row will be output on a new line separated by a newline (/n). sample output of this command would look like:
fluffy,harold,cat,f,1993-02-04,0000-00-00
claws,gwen,cat,m,1994-03-17,0000-00-00