distal-attribute
distal-attribute
distal-attribute
distal-attribute

Multiple CSV Import

User, date Message
Written by lordrom
9 months ago
Category: General
5 posts since Wed, 13 Nov 13
Hi,

I have 345 csv files to import into mysql. All identical, all to be appended to an existing table.

I can import one by one using the import csv file screen, but is there a way to import all files from one directory?

Thanks

John
Written by lordrom
9 months ago
5 posts since Wed, 13 Nov 13
oops, should have been in import/export section...
Written by ansgar
9 months ago
4967 posts since Fri, 07 Apr 06
You could copy the LOAD DATA command produced by HeidiSQL's import dialog from the SQL log once, then paste it 345 times into a query tab, and modify the filename in these commands. Should be the most efficient way.
Written by lordrom
9 months ago
5 posts since Wed, 13 Nov 13
and i used a routine in excel vba to create the strings automatically. real devs wouldn't use vba, but that's my limit.
Sub createsqlloadfiles()


Dim directorytouse

directorytouse = "your directory"


sFileName = Dir(directorytouse)
Range("a1").Select
Do While sFileName <> ""
Application.ScreenUpdating = False
ActiveCell.value = "LOAD DATA LOCAL INFILE 'C:\\Users\\Data\\csv\\" & sFileName & "' IGNORE INTO TABLE `ac88`.`data` CHARACTER SET latin1 FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '" & Chr(34) & "' ESCAPED BY '" & Chr(34) & "' LINES TERMINATED BY '\r\n' (`Date`, blah, blah);"
ActiveCell.Offset(1, 0).Select

sFileName = Dir
Loop

End Sub

Thanks for your help, and hope my routine can speed things up for others.
 

Please login to leave a reply, or register at first.