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

VB ScriptPythonMySQL Server

Avatar of undefined
Last Comment
Scott Fell

8/22/2022 - Mon
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:

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

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Scott Fell

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 ("WScript.shell")
objShell.run "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.

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy