How to insert selected columns from CSV file into MySQL database using LOAD DATA INFILE
P粉549412038
P粉549412038 2023-08-29 13:56:45
0
1
511
<p>I have a CSV file with 10 columns. I just want to select some columns from this file and load them into a MySQL database using the <code>LOAD DATA INFILE</code> command. </p>
P粉549412038
P粉549412038

reply all(1)
P粉232409069

Load data into a table in MySQL and specify columns:

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 ;

@col1,2,3,4 are variables that save csv file columns (assuming 4) name,id are table columns.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template