Friday, June 15, 2012

Save MySQL query results from console

I assume you have logged into your MySQL console. You can save your query result into a file like below:

Text File 

SELECT * FROM your_table .
INTO OUTFILE '/tmp/file.txt'


CSV File

SELECT * FROM your_table 
       INTO OUTFILE '/tmp/file.csv'
       FIELDS TERMINATED BY ','
       ENCLOSED BY '"'
       LINES TERMINATED BY '\n'




Reference : http://www.tech-recipes.com/rx/1475/save-mysql-query-results-into-a-text-or-csv-file/