0

Below is showing error "for f in 'C:\Users\Documents\TEMP*.csv DO LOAD DATA INFILE '"$f"' INTO TABLE TEMP FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES" DONE"

Basically all csv files in the folder which are placed should be inserted into one table

0

You need to script something like this

@echo off
set MYSQLUSER=root
set MYSQLPASS=whateverpassword
set CSVFOLDER="C:\Users\Documents"
cd %CSVFOLDER%
for %f in (.\*.CSV) DO mysql -u%MYSQLUSER% -p%MYSQLPASS% -AN -e"LOAD DATA INFILE '"%CSVFOLDER%\\%f"' INTO TABLE TEMP FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES"

I know the last line will have issues with quotes, so I leave that for you to correct.

  • Thank you Very much Rolando-- I will test this on Tuesday when I'm back to work-- Only question do I need – Dango Dec 24 '16 at 18:37
  • Since I will be logging into local workbench using root account do I need @echo off set MYSQLUSER=root set MYSQLPASS=whateverpassword set CSVFOLDER="C:\Users\Documents" cd %CSVFOLDER% ?? – Dango Dec 24 '16 at 18:52
  • Can I start from here --- for %f in (.*.CSV) DO mysql -u%MYSQLUSER% -p%MYSQLPASS% -AN -e"LOAD DATA INFILE '"%CSVFOLDER – Dango Dec 24 '16 at 18:52
  • I'm getting "Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'for f in 'C:\\Users\\Documents\\TEMP*.csv' DO LOAD DATA INFILE '"$f"' INTO TABL' at line 1 for code "" for f in 'C:\\Users\\Documents\\TEMP*.csv' DO LOAD DATA INFILE '"$f"' INTO TABLE TEMP FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES" DONE" – Dango Dec 27 '16 at 16:13
  • Hi Rolando,since it is not working from workbench, do i have call the script from out side of workbench ? like placing this on server or some thing like that – Dango Dec 28 '16 at 1:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.