简体   繁体   中英

How do i escape both backslash and double quotes in a single query while export MySQL outfile csv

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM