exporting a table in MySQL with columns that have newline characters

后端 未结 2 1958
礼貌的吻别
礼貌的吻别 2021-01-04 20:31

I am pretty inexperienced in SQL, so there should be a simple solution to my problem: I am selecting a table into a comma-separated file, and the column of type TEXT has new

相关标签:
2条回答
  • 2021-01-04 21:05

    Just enclose everything in double quotes perhaps.

    SELECT * FROM db.table INTO OUTFILE 'c:/result.txt'  FIELDS TERMINATED BY ',' ESCAPED BY '\\' ENCLOSED BY '"' LINES TERMINATED BY '\r\n';
    
    0 讨论(0)
  • 2021-01-04 21:08

    Novikov is correct but you could also escape the new line characters while exporting.

    SELECT REPLACE(`fieldname1`,'\n','\\n'),`fieldname2` FROM db.table INTO OUTFILE 'c:/result.txt'  FIELDS TERMINATED BY ',' ESCAPED BY '\\' ENCLOSED BY '"' LINES TERMINATED BY '\r\n';
    

    This will then replace all the new line characters with the text string '\n' This may not be what you want in the output though.

    DC

    0 讨论(0)
提交回复
热议问题