Importing a CSV File into MySQL Without an ID Field
The issue arises when attempting to import a CSV file into a MySQL table that lacks an ID field and lacks column headers. This guide will provide instructions on how to import the data while skipping the first column (ID) and allowing MySQL to automatically assign values to the auto-increment ID field.
Steps:
LOAD DATA INFILE 'path/to/file.csv' INTO TABLE your_table FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' SET>
Replace 'path/to/file.csv' with the actual path to your CSV file. Replace 'your_table' with the name of the target table.
Note: Ensure that the ID field in your table is set to auto-increment before performing the import. This will allow MySQL to automatically assign unique values to the ID column for each imported record.
The above is the detailed content of How to Import a CSV File into MySQL Without an ID Field?. For more information, please follow other related articles on the PHP Chinese website!