I have about 28 csv files and I need to import this into database as 28 tables. I tried many things but just couldn't find a way.
2 Answers
You can link MYSQL directly to it and upload the information using the following SQL syntax.
load data local infile 'uniq.csv' into table tblUniq
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
Read more here : LOAD DATA INFILE
3 Comments
Pink
@ Teez: Thanks for the reply but, I have used this query and it will only take in 1 file. I have around 28 files, I wanted to find a query by which all 28 files would get into 28 tables in a single query
Pink
@ Teez: Thanks a lot. I will try to write a script as that would help me learn more
It's a good solution for Windows-users. Just create a text file "import.bat" with code, after that run it.
@ECHO off
FOR %%I In (db\*.sql) DO mysqlimport.exe --local -uroot -proot vipamoda %%I
PAUSE
More complex code which importing first SQL-structure, then import TXT-data:
@ECHO off
FOR %%I IN (db\*.sql) DO (
mysql.exe -uroot -proot vipamoda < %%~dpnI.sql
mysqlimport.exe --local -uroot -proot vipamoda %%~dpnI.txt
)
PAUSE
And dump code for this import code is:
mysqldump.exe --compact --add-drop-table --tab=db -uroot -proot vipamoda