MySQL LOAD DATA INFILE: works, but unpredictable line terminator

前端 未结 7 910
走了就别回头了
走了就别回头了 2020-12-25 14:58

MySQL has a nice CSV import function LOAD DATA INFILE.

I have a large dataset that needs to be imported from CSV on a regular basis, so this feature is

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-25 15:35

    You can use LINES STARTING to separate usual line endings in text and a new row:

    LOAD DATA LOCAL INFILE '/home/laptop/Downloads/field3-utf8.csv' 
    IGNORE INTO TABLE Field FIELDS 
    TERMINATED BY ';' 
    OPTIONALLY ENCLOSED BY '^' 
    LINES STARTING BY '^' 
    TERMINATED BY '\r\n' 
    (Id, Form_id, Name, Value)
    

    For usual CSV files with " enclosing chars, it will be:

    ...
    LINES STARTING BY '"' 
    ...
    

提交回复
热议问题