I have 31 csv file in my pc. I want to load all these csv file into a single table in mysql. is there anyway to do this using sql query??
Asked
Active
Viewed 3,004 times
3 Answers
0
Use LOAD DATA INFILE
LOAD DATA INFILE 'c:/part/yourfile.csv'
INTO TABLE NameOfTable
FIELDS TERMINATED BY ';' -- because CSV
ENCLOSED BY '"' -- I don't know your file
LINES TERMINATED BY '\n' -- Probably this
IGNORE 1 ROWS; -- If it has to be
And again for all your CSV

Hearner
- 2,711
- 3
- 17
- 34
0
Assuming your pc is a windows pc, if yes then use below command one by one for each file-
LOAD DATA INFILE 'c:\\temp\\your_file.csv'
INTO TABLE table_name
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES;
If you don't have header line then remove "IGNORE 1 LINES".
If you are using linux or mac then there will be little bit change in syntax.

Zafar Malik
- 6,734
- 2
- 19
- 30
-3
Try to first cat all of the files into a single csv
cat file1.csv file2.csv > outputfile.csv
or
cat *.csv > outputfile.csv
Then use the LOAD DATA INFILE
to import outputfile.csv one time

Sherif
- 11,786
- 3
- 32
- 57