Vincent L
Vincent L

Reputation: 739

(Windows batch file) SET was unexpected at this time

I am going crazy over this. I am trying to write a tiny batch file that loads all the .csv files from a folder into a MySQL database on my machine.

I am running this .bat directly from the folder where all the files are.

SETLOCAL ENABLEDELAYEDEXPANSION

for %%f in (*.csv) do (
    mysql -e "LOAD DATA INFILE 'C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/realtime/%%f' IGNORE INTO TABLE db.my_table FIELDS ENCLOSED BY '\"' TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 1 LINES (@TIME, NAME, ID, PRICE, LOSS) SET TIME = STR_TO_DATE(@TIME, '%c/%e/%Y %H:%i')" -u root -password='XXXXXXXXXX'
)

I am always getting the error message:

SET was unexpected at this time.

And from the ECHO, it seems like the variables in the STR_TO_DATE are changed as well.

What am I doing wrong?

Thanks!

Upvotes: 0

Views: 825

Answers (2)

Michael
Michael

Reputation: 108

for what? I'm guessing for /f try this:

for /f %%f in (*.csv) do (...

You didn't choose the for statement. Loop or Read.

Upvotes: 0

Magoo
Magoo

Reputation: 80033

Escape ) with a caret ^) in the mysql statement.

cmd sees ) as end-of-if-conditional or end-of-do and needs to be told "this is data, just a character" by escaping the paren (also any redirectors)

Upvotes: 1

Related Questions