mysql into outfile

by Jayanthi 2013-06-26 14:31:22

mysql into outfile

INTO OUTFILE writes the selected rows to a file.It is useful to generate customize reports.

Syntax

{QUERY} INTO OUTFILE {FILEPATH}



Example 1

select * from category where staus='active' INTO OUFILE "/home/jey/sql.csv"



Example 2

select * from category where staus='active' INTO OUFILE "/home/jey/csql.xls"



Once created csv,xls or pdf file cann't overwrite.
INTO OUTFILE must be the last statement in the query.


Customize the standard format using TERMINATED,ENCLOSED

Examplw 3

SELECT id,name,price FROM product INTO OUTFILE '/tmp/all.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY 'n'


OUTPUT 3

"1","M100","400.00"
"2","DS1000","500.00" ...





912
like
0
dislike
0
mail
flag

You must LOGIN to add comments