MySQL export into outfile : CSV escaping chars

前端 未结 6 1946
暗喜
暗喜 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:18

    I think your statement should look like:

    SELECT id, 
       client,
       project,
       task,
       description, 
       time,
       date  
      INTO OUTFILE '/path/to/file.csv'
      FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
      LINES TERMINATED BY '\n'
      FROM ts
    

    Mainly without the FIELDS ESCAPED BY '""' option, OPTIONALLY ENCLOSED BY '"' will do the trick for description fields etc and your numbers will be treated as numbers in Excel (not strings comprising of numerics)

    Also try calling:

    SET NAMES utf8;
    

    before your outfile select, that might help getting the character encodings inline (all UTF8)

    Let us know how you get on.

提交回复
热议问题