soni8010
soni8010

Reputation: 347

Export mysql data to csv and download csv file

I want to export MySQL data to csv file and then want to download that csv file.I have query like.

SELECT * INTO OUTFILE '/tmp/result.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY ‘\\’
LINES TERMINATED BY '\n'
FROM cdr WHERE   calldate >= '2015-04-01 00:00:00' 
AND  calldate <= '2015-04-06 00:00:00';

Which is not working.Give me error like.

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '‘\\’
LINES TERMINATED BY '\n'

Upvotes: 0

Views: 254

Answers (1)

Boris N
Boris N

Reputation: 857

You should escape the '\' sign like this: '\\', so your request will be:

"SELECT * INTO OUTFILE '/tmp/result.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' FROM cdr WHERE calldate >= '2015-04-01 00:00:00' AND calldate <= '2015-04-06 00:00:00'";

Upvotes: 1

Related Questions