Wednesday, May 22, 2013

Batch file to deploy a Mysql script


This dos batch script can be used to execute a mysql script.  Note: mysql.exe has to be available in the same folder.Replace <> with your schema name.

@ECHO OFF REM TODO Create schema if does not exist. REM TODO Display tables when completed Set /P script=Please enter the script file name e.g. create.sql: IF "%script%"=="" GOTO ERROR_MISSINGPARAM If NOT Exist "%script%" SET script="%~dp0\%script%" If NOT Exist "%script%" GOTO ERROR_FILENOTEXIST SET dbname =appdb SET /P host=Please enter database hostname/ip, press enter for "localhost": IF "%host%"=="" SET host=127.0.0.1 SET /P user=Please enter database username, press enter for "root": IF "%root%"=="" SET user=root
Echo Running script %script% on to database %user%@%host%/%dbname% "%~dp0\mysql.exe" -u%user% -h%host% -p %dbname% < "%script%" IF %ERRORLEVEL% EQU 0 ( ECHO Database script execution complete. ) ELSE ( ECHO Database or script errors occurred. ) GOTO END :ERROR_MISSINGPARAM ECHO You did not enter one or more required values. GOTO END :ERROR_FILENOTEXIST ECHO Script file does not exist GOTO END Echo end :END ECHO Press any key to quit! PAUSE > nul


No comments:

Post a Comment