Reputation: 347
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
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