@echo off
::以下1~8参数请按自己的情况修改;其他的不需要修改
::=======================视各环境情况修改=================
:: 1,备份目标主机
set dbhost=127.0.0.1
:: 2,数据库端口
set dbport=3306
:: 3,本地MYSQL的bin路径
set mysqlbin="C:\Program Files\MySQL\MySQL Server 5.5\bin"
:: 4,数据库名
set dbname=wuchangekp
:: 5,MYSQL用户名
set user=root
:: 6,MYSQL密码
set passwd=wc!@#2024
:: 7,备份保存目录
set files=E:\Mysqlbak\
:: 8,保留备份天数
set days=7
::=================================================================
:: The following content does not need to be modified
:: 以下内容不需要修改
::=================================================================
IF NOT EXIST "%files%" MD "%files%"
set "Ymd=%date:~,4%%date:~5,2%%date:~8,2%"
echo .
echo ------------------***** ***----------------------------
echo ------------------***** 正在执行MySQL数据库备份 ***----------------------------
echo ------------------***** ***----------------------------
echo 正在导出KK数据,请勿关闭本窗口...
%mysqlbin%\mysqldump.exe --opt -u%user% -p%passwd% -h%dbhost% -P%dbport% %dbname% > %files%\wuchang_db_%Ymd%.sql
forfiles /P %files% /D -%days% /M *.sql /C "cmd /c del @file" >nul 2>nul
echo .
echo .
echo 备份完成! 备份文件保存在 %files%\wuchang_db_%Ymd%.sql
::9拷贝文件到251服务器E:\dbback文件夹
xcopy /y "E:\Mysqlbak\wuchang_db_%Ymd%.sql" "\\192.168.1.251\dbback"
ping -n 10 127.0.0.1>nul
exit
标签:set,windows,db,备份,sql,files%,echo,mysql,dos From: https://www.cnblogs.com/jianglz/p/17979914