How to LOAD DATA INFILE in mysql with first col being Auto Increment?
LOAD DATA INFILE '/tmp/data.csv'
INTO TABLE your_table
FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r'
(AField, BField);
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;
you can "omit" ID field in data row by placing delimiter sign in the beginning of a row, like this (for table schema ID,AField,BField
):
,afieldvalue,bfieldvalue
...
SQL engine will assign NULL
to ID
field while reading such csv file
Try to use NULL as the value in the csv file for the ID field.