How to LOAD DATA INFILE in mysql with first col being Auto Increment?

后端 未结 7 2001
离开以前
离开以前 2020-11-30 02:05

Currently, We have a table similar to this:

---------------------
ID | AField | BField|
---------------------

The ID is Auto Increment

相关标签:
7条回答
  • 2020-11-30 02:45
    LINES TERMINATED BY '\r\n' 
    

    That was the key to success for me when using a text file

    0 讨论(0)
  • 2020-11-30 02:47

    If you have only a small number of columns, you can just name them: LOAD DATA LOCAL INFILE 'myfile.txt' INTO TABLE mytable (AField); (assuming only ID & AField)

    0 讨论(0)
  • 2020-11-30 02:52

    Try to use NULL as the value in the csv file for the ID field.

    0 讨论(0)
  • 2020-11-30 02:53
    LOAD DATA INFILE '/tmp/data.csv'
    INTO TABLE your_table
    FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r'
    (AField, BField);
    
    0 讨论(0)
  • 2020-11-30 03:09

    The best thing to do is just include the 2 non-auto-increment columns in the CSV, and then explicitly set the ID column to NULL in the load data infile statement.

    Something like this:

    LOAD DATA INFILE '/tmp/data.csv'
    INTO TABLE your_table
    FIELDS TERMINATED BY ','
    (AField, BField)
    SET ID = NULL;
    
    0 讨论(0)
  • 2020-11-30 03:11

    NULL in CSV file is read as a STRING in MySQL. If you want to have null values in a MySQL column instead use \N in place of `NULL. This will fix the issue and you will get the required result.

    0 讨论(0)
提交回复
热议问题