Windows – Auto Backup Mysql Database

1. Save command lines below as .bat file

2. Set Task schedule in windows.

@echo off
SET MysqlBinPath=MySQL\bin的路徑( eg. D:\Mysql\bin )
SET BackupPath=backup folder (eg. D:\backup)
SET DBhost=machine ip ( eg. 211.58.1.2)
SET DBuser=database username (eg. root)
SET DBpass=database password (eg. 12345)
SET DBname=databaseName
SET Argument=–opt –compress –force –default-character-set=utf8
REM
/* no need to fix below */
REM
/* Get date。
FOR /F “tokens=1-4 delims=/ ” %%a IN (“%date%”) DO (
SET _MyDate=%%a-%%b-%%c %%d
)
REM /* Export .sql filename with date。 */
echo database %DBname% during the backup……
“%MysqlBinPath%\mysqldump” –host=%DBhost% –user=%DBuser% –password=%DBpass% %Argument% %DBname%  >; “%BackupPath%\%_MyDate%.sql”
REM
/* Debug Messages */
IF
NOT %ERRORLEVEL% == 0 (
del “%BackupPath%\%_MyDate%.sql
echo.
echo Something wrong! Plz refer to the messages above!
pause
)

Reference from: http://www.ge.net.tw/?q=node/521