简体   繁体   中英

(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!

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM