Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The procedure for importing data into MySQL using LOAD DATA INFILE while ensuring that the first column is set to Auto Increment is as follows:

  1. Create a table with an ID column set to AUTO_INCREMENT and the rest of the columns specified as needed.

  2. Open the file that contains the data to be imported.

  3. Modify the file to remove any headers or other unwanted information.

  4. Run the following command in MySQL: LOAD DATA INFILE 'filename.txt' INTO TABLE tablename FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES;

Note: the FIELDS TERMINATED BY ',' option specifies that values in the file are separated by comma, and the OPTIONALLY ENCLOSED BY '"' option specifies that values may be surrounded by quotation marks. The LINES TERMINATED BY '\r\n' option specifies that each line in the file ends with a carriage return and line feed.

  1. If the first column in the file is not an ID column, add a placeholder value (such as NULL) for the ID column in each line of the file.

  2. Once the data is loaded into the table, MySQL will automatically assign unique ID numbers to each row in the table based on the AUTO_INCREMENT setting of the ID column.