日期:2014-05-16  浏览次数:20632 次

逐日备份MySQL数据库的Windows脚本
利用Windows的日程管理器(Scheduler)每日定时执行如下内容的批处理文件:
@ECHO OFF

for /f "tokens=1-4 delims=- " %%a in ('date/t') do (
set yy=%%a
set mm=%%b
set dd=%%c
set dw=%%d
)
echo %dw%
echo %mm%
echo %dd%
echo %yy%

SET backupdir=F:\bak\mysql
SET mysqldir="C:\Program Files\MySQL\MySQL Server 5.1"
SET dbname=test
SET dbuser=root
SET dbpasswd=123456
SET filename=%dbname%_%yy%-%mm%-%dd%.sql							

@ECHO Beginning backup of %dbname%...

%mysqldir%\bin\mysqldump -u %dbuser% -p%dbpasswd% --default-character-set=gbk %dbname% > %backupdir%\%filename%

@ECHO Done!