Multiple CSV Import

[expired user #7406]'s profile image [expired user #7406] posted 10 years ago in General Permalink
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
[expired user #7406]'s profile image [expired user #7406] posted 10 years ago Permalink
oops, should have been in import/export section...
ansgar's profile image ansgar posted 10 years ago Permalink
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.
[expired user #7406]'s profile image [expired user #7406] posted 10 years ago Permalink
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.