How to skip columns in CSV file when importing into MySQL table using LOAD DATA INFILE?

前端 未结 4 1452
猫巷女王i
猫巷女王i 2020-11-27 11:58

I\'ve got a CSV file with 11 columns and I have a MySQL table with 9 columns.

The CSV file looks like:

col1, col2, col3, col4, col5, col6, col7, col         


        
4条回答
  •  时光取名叫无心
    2020-11-27 12:37

    From Mysql docs:

    You can also discard an input value by assigning it to a user variable and not assigning the variable to a table column:

    LOAD DATA INFILE 'file.txt'  
    INTO TABLE t1 (column1, @dummy, column2, @dummy, column3);
    

提交回复
热议问题