MySQL export into outfile : CSV escaping chars

前端 未结 6 1945
暗喜
暗喜 2020-11-27 13:44

I\'ve a database table of timesheets with some common feilds.

id, client_id, project_id, task_id, description, time, date 

There are more b

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 14:29

    Without actually seeing your output file for confirmation, my guess is that you've got to get rid of the FIELDS ESCAPED BY value.

    MySQL's FIELDS ESCAPED BY is probably behaving in two ways that you were not counting on: (1) it is only meant to be one character, so in your case it is probably equal to just one quotation mark; (2) it is used to precede each character that MySQL thinks needs escaping, including the FIELDS TERMINATED BY and LINES TERMINATED BY values. This makes sense to most of the computing world, but it isn't the way Excel does escaping.

    I think your double REPLACE is working, and that you are successfully replacing literal newlines with spaces (two spaces in the case of Windows-style newlines). But if you have any commas in your data (literals, not field separators), these are being preceded by quotation marks, which Excel treats much differently than MySQL. If that's the case, then the erroneous newlines that are tripping up Excel are actually newlines that MySQL had intended as line terminators.

提交回复
热议问题