Inserting Specific Columns from CSV to MySQL via LOAD DATA INFILE
In this scenario, you wish to selectively import specific columns from a CSV file into a MySQL database using the LOAD DATA INFILE command. To achieve this, follow these steps:
LOAD DATA LOCAL INFILE 'file.csv' INTO TABLE t1 FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (@col1,@col2,@col3,@col4) set name=@col4,id=@col2 ;
In this statement, the following parameters are used:
This query allows you to select only the specified columns from the CSV file and insert them into the corresponding columns in the MySQL table.
The above is the detailed content of How to Import Specific CSV Columns into MySQL using LOAD DATA INFILE?. For more information, please follow other related articles on the PHP Chinese website!