How to insert selected columns from a CSV file to a MySQL database using LOAD DATA INFILE

后端 未结 6 817
甜味超标
甜味超标 2020-11-27 10:13

I have a CSV file which contains 10 columns. I want to select only some columns from that file and load them into a MySQL database using the LOAD DATA INFILE co

6条回答
  •  天涯浪人
    2020-11-27 11:03

    LOAD DATA INFILE 'file.csv'
      INTO TABLE t1
      (column1, @dummy, column2, @dummy, column3, ...)
    FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '"'
    LINES TERMINATED BY '\r\n';
    

    Just replace the column1, column2, etc.. with your column names, and put @dummy anwhere there's a column in the CSV you want to ignore.

    Full details here.

提交回复
热议问题