-3

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??

1

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

-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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.