Link to home
Start Free TrialLog in
Avatar of KzKrew
KzKrewFlag for United States of America

asked on

Import CSV to MySQL Table

Team Experts
I am looking to put the following sequence of MySql commands into a VB Script to import a TestFile.csv into a test table.
I can import at command line but looking to use VBS script to pull in files from other locations. Open to using Python if that is a better option
Any advice is appreciated.


Open command prompt – navigate to C:\Program Files\MySQL\MySQL Server 8.0>cd bin --- Run the following commands

mysql --local-infile=1 -uUserName -pPassword      
use tblTest load data local infile 'C:/TestFolder/TestFile.csv' into table tbl_test fields terminated by ',' optionally enclosed by '"' ignore 1 rows;         ‘Ignore first line header

Open in new window

Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Never tried but sounds like you just want to use VBScript as a wrapper to an OS command?

There are examples on the Internet:,675029,675062#msg-675062

It appears Python has some nice modules to import that removes the need for shelling out to the OS:
Avatar of Tomas Helgi Johannsson
Tomas Helgi Johannsson
Flag of Iceland image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I can import at command line but looking to use VBS script  

You can simply run your command line using vbs. An example from the link below:
Dim objShell
Set objShell = WScript.CreateObject ("") "cmd /K CD C:\ & Dir"
Set objShell = Nothing

Open in new window

Otherwise, you can just rewrite everything in vbscript from the connection string, to to the file upload (if needed), parsing the data to format for the SQL, running the database query etc.