MySQL export into outfile : CSV escaping chars

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

    Here is what worked here: Simulates Excel 2003 (Save as CSV format)

    SELECT 
    REPLACE( IFNULL(notes, ''), '\r\n' , '\n' )   AS notes
    FROM sometables
    INTO OUTFILE '/tmp/test.csv' 
    FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '"'
    LINES TERMINATED BY '\r\n';
    
    1. Excel saves \r\n for line separators.
    2. Excel saves \n for newline characters within column data
    3. Have to replace \r\n inside your data first otherwise Excel will think its a start of the next line.

提交回复
热议问题