[Windows] Script to update a database without combining SQL

This is a script that I wrote a long time ago that updates a database by importing the files one at a time. It may be useful for people who have problems importing the large combined SQL.

This particular example updates the AUTH database but you can easily change some of the variables to update any database (not even limited to TrinityCore).

Enjoy!

NOTE:

If you get errors importing the “locale” SQL files, try adding this to the commandline under the DO_IMPORT section: –default-character-set=utf8

[CODE]
@ECHO off
cls

REM Script: Updates TrinityCore AUTH database
REM Author: MrSmite
REM
REM Usage:
REM 1. Copy all the AUTH .SQL files that you want to import into a temporary folder
REM 2. Change the variables between the BEGIN and END LOCAL VARIABLES headers
REM 3. Run the script

REM ########## BEGIN LOCAL VARIABLES ##########

REM The path / binary for your MySQL client
SET sql_bin=C:Program FilesMySQL5.5binmysql.exe

REM The user / password for your AUTH database
SET user_name=mySqlUser
SET user_auth=mySqlPass

REM The IP address and port MySQL is listening on
SET db_host=127.0.0.1
SET remote_port=11111

REM The name of the database to update
SET db_name=trinityAuth

REM The directory where all the AUTH .SQL files are located (recommended a subfolder where this script is)
REM Note: DO NOT point this to the sql folder in your repo:
REM 1. It will import unwanted SQL files
REM 2. The script deletes the SQL files on success
REM
SET src_dir=

REM ########## END LOCAL VARIABLES ##########

REM Error tracking
SET bErr=0

ECHO Press any key to update your AUTH database
PAUSE>NUL
ECHO.

IF EXIST %src_dir%*.sql (GOTO PROCESS_FILES) ELSE GOTO NO_FILES

:PROCESS_FILES
REM “tokens=" is required to properly catch filenames with spaces
FOR /f "tokens=
” %%a IN (‘dir /b %src_dir%*.sql’) DO (
call :DO_IMPORT %%a
)

GOTO SCRIPT_DONE

:DO_IMPORT
ECHO Importing %1
“%sql_bin%” -u%user_name% -p%user_auth% -h%db_host% -P%remote_port% %db_name% < %src_dir%%1

IF “%ERRORLEVEL%” EQU “0” (
REM Do Nothing (Could also check NEQU for <>)
) ELSE (
SET bErr=1
ECHO.
PAUSE
ECHO.
)

GOTO :EOF

:NO_FILES
ECHO No files to import (or SRC_DIR not defined), press any key to exit
PAUSE>NUL
GOTO BATCH_EXIT

:SCRIPT_DONE
REM Cleanup if no error
IF “%bErr%” EQU “0” (del %src_dir%*.sql)

ECHO.
ECHO Finished, press any key to exit
PAUSE>NUL

:BATCH_EXIT[/CODE]