1 @title MySQL备份脚本 2 @echo off 3 @echo [email protected]:3306 4 set host=127.0.0.1 5 set port=3306 6 set user=root 7 @echo 请输入数据库密码 8 set /p password= 9 @echo 请输入需要备份的数据库 10 @set /p database= 11 set mysqldumppath=d:\mysql\bin 12 set resultfilepath=e: 13 set curdate=%date:~0,4%-%date:~5,2%-%date:~8,2% 14 set curmon=%date:~0,4%%date:~5,2% 15 set curtime=%time:~0,2% 16 if "%curtime%"=="0" set curtime=00 17 if "%curtime%"=="1" set curtime=01 18 if "%curtime%"=="2" set curtime=02 19 if "%curtime%"=="3" set curtime=03 20 if "%curtime%"=="4" set curtime=04 21 if "%curtime%"=="5" set curtime=05 22 if "%curtime%"=="6" set curtime=06 23 if "%curtime%"=="7" set curtime=07 24 if "%curtime%"=="8" set curtime=08 25 if "%curtime%"=="9" set curtime=09 26 set curtime=%curtime%-%time:~3,2%-%time:~6,2% 27 set resultfile=%database%_%curdate%_%curtime%.sql 28 @%mysqldumppath%\mysqldump.exe %database% --result-file=%resultfilepath%\%resultfile% --complete-insert --user=%user% --password=%password% --host=%host% --port=%port% 29 @echo 操作结束 30 pause 31 @echo on 32 exit
可以简单修改下脚本将要输入的内容写定,加入计划任务中,每次开机自动备份一次MySQL数据库。