When working with large comma-separated value (CSV) files, it becomes necessary to selectively import specific columns into a MySQL database. The LOAD DATA INFILE command offers a convenient way to achieve this goal.
To selectively import chosen columns from a CSV file, use the following syntax:
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 ;
Here's a breakdown:
By following these steps, you can efficiently extract and import only the desired columns from a CSV file into your MySQL database.
Das obige ist der detaillierte Inhalt vonWie importiere ich bestimmte Spalten aus einer CSV-Datei in MySQL?. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!