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
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
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:
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:
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.
Set objShell = WScript.CreateObject ("WScript.shell")
objShell.run "cmd /K CD C:\ & Dir"
Set objShell = Nothing