一、编写脚本
echo 取日期、时间变量值
set yy=%date:~0,4%
set mm=%date:~5,2%
set dd=%date:~8,2%
if /i %time:~0,2% lss 10 set hh=0%time:~1,1%
if /i %time:~0,2% geq 10 set hh=%time:~0,2%
set mn=%time:~3,2%
set ss=%time:~6,2%
set date=%yy%%mm%%dd%
set time=%hh%%mn%%ss%
%这里不要具体时分数据,要的话可以追加time%
set filename=%date%
%赋值等号两边不能有空格%
set mysqldumpPath="C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqldump.exe"
set dbName=whx_xc
set dbUser=root
set dbPwd=123456
set outpurDir=E:/MySqlBackUp/backup/
set outputFileName=%outpurDir%%dbName%_%filename%.sql
echo %outputFileName%
%mysqldumpPath% -u%dbUser% -p%dbPwd% --opt --default-character-set=utf8 -e --triggers -R --hex-blob --flush-logs -x %dbName% > %outputFileName%
二、创建计划任务