[HOW TO] Export mysql result to csv file

Hello,

Export mysql result to csv file is necessary. It is useful in case of you need to send the result to developer or others.

You can follow:

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

What it means?
FIELDS TERMINATED BY ',' :the fields will be separated by commas,
ENCLOSED BY '"' :each field will be enclosed in “double quotes,”
LINES TERMINATED BY '\n'; :each row will be output on a new line separated by a newline (\n)

Hope this help!

Thank you for reading this article, please a comment if you are interested.

Tiến Phan - R0039

Knowledge is Endless

Sharing for Success

0 nhận xét:

Post a Comment