Tuesday 12 March 2013

Batch file to execute MySQL scripts


@echo off
ECHO %USERNAME% started the File Execution Process at %TIME%  >status.txt

for %%f in (*.sql) do (
C:\wamp\bin\mysql\mysql5.5.20\bin\mysql -u root --delimiter=// < %%f >>status.txt
pause; 

)



Can someone extend this to let the files be executed in accordance of their modified time stamps

1 comment:

  1. I found the way to order files based on timestamp. dir command can be used to list files. We can use options to order by date and generate the list of files. After some try and errors, I found out that we can use following commands to import sqls based on their dates:


    @echo off
    ECHO %USERNAME% started the File Execution Process at %TIME% >status.txt

    dir *.sql /b /o:d > executeFiles.txt

    for /f "tokens=*" %%f in ( executeFiles.txt ) do (
    C:\wamp\bin\mysql\mysql5.5.24\bin\mysql -u root testdcrdx --delimiter=// < %%f >>status.txt
    pause;

    )

    ReplyDelete