3
SELECT `col 1`, `col 2`, `col 3`, `col 4`, `col 5`
FROM table_name
INTO OUTFILE '/test.csv'
CHARACTER SET utf8
FIELDS TERMINATED BY ','

OPTIONALLY ENCLOSED BY '\"' ESCAPED BY '\"'

LINES TERMINATED BY '\n'

I've done the query above to escape double quotes, but I want to escape both the backslash and double quotes characters in same query.

Dhileep
  • 47
  • 8
  • Possible duplicate of [How do I escape special characters in MySQL?](https://stackoverflow.com/questions/881194/how-do-i-escape-special-characters-in-mysql) – R B May 29 '18 at 04:19
  • I think it would help your question to show us how you want the final data to look, highlighting double quotes/backslash where appropriate. – Tim Biegeleisen May 29 '18 at 04:21

1 Answers1

1

Possibly it is due to enter character exists on any of your fields, not because of backslash. Try replacing enter character using REPLACE function, possibly you think that column has a enter character. Please find the sample query below.

SELECT COLUMN1,COLUMN2,REPLACE(COLUMNNAME , '\n', ' ') as COLUMNNAME,... 
INTO OUTFILE '/test.csv' 
CHARACTER SET utf8  
FIELDS TERMINATED BY ',' 
OPTIONALLY ENCLOSED BY '\"' 
ESCAPED BY '\"' 
LINES TERMINATED BY '\n'
FROM tableName

Hope it helps.

Ashok
  • 128
  • 1
  • 8