title: Batch command FOR Loop to load MySQL Data - (was unexpected at this time)
body: <p>I am in trouble with FOR LOOP command using a batch file...</p>
  
  <p>Let's see if someone knows how can I solve this issue, because I can not figure out how to solve it. My .bat file is more less like example below...</p>
  
  <pre><code>ECHO 'Initializing data loading'
  
  FOR %%I In (C:\TempFolder\*.csv) DO ( 
  
      ECHO '%%~nxI'
  
      mysql.exe -h dbInstance -uUser -pPass dbase --local-infile -e "LOAD DATA LOCAL INFILE '"%%~nxI"' INTO TABLE table1 CHARACTER SET Latin1 COLUMNS TERMINATED BY ';' LINES TERMINATED BY '\n' IGNORE 1 LINES" 
  
      mysql.exe -h dbInstance -uUser -pPass dbase "OPTIMIZE TABLE table1"
  
  )   
  </code></pre>
  
  <p>My output:</p>
  
  <pre><code>C:\DtImport&gt;ECHO 'Initializing data loading'
  'Initializing data loading'
  as was unexpected at this time.
  </code></pre>
  
  <p>If i execute only the first mysql command, it works fine... Just, when I try to execute more than one command, I ve got this error.</p>
  
  <p>This is the output when I remove the second mysql command as It was on example above</p>
  
  <pre><code>C:\DtImport&gt;test
  'Initializing data loading';
  'EXP_1997.csv'
  mysql: [Warning] Using a password on the command line interface can be insecure.
  
  'EXP_1998.csv'
  mysql: [Warning] Using a password on the command line interface can be insecure.
  </code></pre>
  
  <p>Someone can help me with this issue? </p>
  
  <p>All .bat file below</p>
  
  <pre><code> @echo off
  
  ECHO 'Movendo arquivos que serão utilizados para carga...'
  
  
  ECHO 'Iniciando carga. Aguarde!'
  
  FOR %%I In (C:\DtImport\*.csv) DO ( 
  
  ECHO '%%~nxI'
  
      mysql.exe -h dinstance -uUser -pPassword dataBase --local-infile -e "LOAD DATA LOCAL INFILE '"%%~nxI"' INTO TABLE temp_table CHARACTER SET Latin1 COLUMNS TERMINATED BY ';' LINES TERMINATED BY '\n' IGNORE 1 LINES" 
  
  mysql.exe -h dinstance -uUser -pPassword dataBase -e "INSERT INTO imp_table (select REPLACE(CONCAT(TRIM(col1),'-',TRIM(col2),'-1'),'\"', ''), REPLACE(TRIM(col3),'\"', ''), REPLACE(TRIM(col4),'\"', ''), REPLACE(TRIM(col5),'\"', ''), REPLACE(TRIM(col6),'\"', ''), REPLACE(TRIM(col7),'\"', ''), REPLACE(TRIM(col8),'\"', ''), REPLACE(TRIM(col9),',','.'), REPLACE(TRIM(col10),',','.'), REPLACE(TRIM(col11),',','.') FROM temp_table)"
  
  mysql.exe -h dinstance -uUser -pPassword dataBase -e "DELETE FROM temp_table"
  
  mysql.exe -h dinstance -uUser -pPassword dataBase -e "OPTIMIZE TABLE temp_table"
  
  
  ) 
  ECHO 'TERMINADO'
  
  PAUSE
  </code></pre>