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

后端 未结 6 805
甜味超标
甜味超标 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 10:48

    if you have number of columns in your database table more than number of columns in your csv you can proceed like this:

    LOAD DATA LOCAL INFILE 'pathOfFile.csv'
    INTO TABLE youTable 
    CHARACTER SET latin1 FIELDS TERMINATED BY ';' #you can use ',' if you have comma separated
    OPTIONALLY ENCLOSED BY '"' 
    ESCAPED BY '\\' 
    LINES TERMINATED BY '\r\n'
    (yourcolumn,yourcolumn2,yourcolumn3,yourcolumn4,...);
    

提交回复
热议问题