Thursday, August 11, 2011

How to save MySQL query results into a text or CSV file

Below query writes resultsset to .txt file :-

SELECT order_id,product_name,qty
FROM orders
INTO OUTFILE '/tmp/orders.txt'



To make csv , try this one :-

SELECT order_id,product_name,qty
FROM orders
INTO OUTFILE '/tmp/orders.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n' ;



phewww...