Showing posts with label mysql result to csv file using shell. Show all posts
Showing posts with label mysql result to csv file using shell. Show all posts

Tuesday, December 11, 2012

How to output MySQL query results in csv format

SELECT 'Order Id', 'Product Name', 'Quantity'
UNION
(
SELECT order_id,product_name,qty
FROM orders
INTO OUTFILE 'C:\\tmp\\orders.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
)