@echo off & setlocal ENABLEEXTENSIONS :: ---------- 配置项 ---------- :: 备份放置的路径,加 set BACKUP_PATH=E:Backup :: 要备份的数据库名称,多个用空格分隔 set DATABASES=test :: MySQL 用户名 set USERNAME=root :: MySQL 密码 set PASSWORD=centos :: MySQL Bin 目录,加 :: 如果可以直接使用 mysqldump(安装时添加 MySQL Bin 目录到了环境变量),此处留空即可 set MYSQL="C:Program FilesMySQLMySQL Server 5.7inmysqldump.exe" :: ---------- 以下请勿修改 ---------- set YEAR=%date:~0,4% set MONTH=%date:~5,2% set DAY=%date:~8,2% :: 如果在 dos 下输入 time 返回的不是 24 小时制(没有 0 填充),请自行修改此处 set HOUR=%time:~0,2% set MINUTE=%time:~3,2% set SECOND=%time:~6,2% set DIR=%BACKUP_PATH%%YEAR%\%MONTH%\%DAY% set ADDON=%YEAR%%MONTH%%DAY%%HOUR%%MINUTE%%SECOND% echo %DIR% echo %ADDON% :: create dir if not exist %DIR% ( mkdir %DIR% 2>nul ) if not exist %DIR% ( echo Backup path: %DIR% not exists, create dir failed. goto exit ) cd /d %DIR% %MYSQL% -u%USERNAME% -p%PASSWORD% %DATABASES%>%DATABASES%.%ADDON%.sql 2>nul echo export complete