一、编写批处理脚本
@echo off
forfiles /p "E:\mysql\MySQL BackUp" /m backup_*.sql -d -30 /c "cmd /c del /f @path"
set "Ymd=%date:~0,4%%date:~5,2%%date:~8,2%0%time:~1,1%%time:~3,2%%time:~6,2%"
"E:\mysql\MySQL Server 5.6\bin\mysqldump" --opt --single-transaction=TRUE --user=root --password=123456 --host=127.0.0.1 --protocol=tcp --port=3306 --default-character-set=utf8 --single-transaction=TRUE --routines --events "yumi_website" > "E:\mysql\MySQL BackUp\backup_%Ymd%.sql"
@echo on
运行时间在10点-23点之间,用%time:~0,2%%time:~3,2%%time:~6,2%;
运行时间在0点到9点之间,用%time:~1,1%%time:~3,2%%time:~6,2%
二、用Windows计划任务程序定时运行脚本
开始 -> Windows管理工具 -> 任务计划程序,在任务计划程序库中选择一个文件较少的文件夹,创建基本任务 -> ... -> 选择脚本
参考:
https://blog.csdn.net/freezingxu/article/details/78884962
https://blog.csdn.net/weixin_34368949/article/details/93591260
https://www.cnblogs.com/kxxx/p/10729462.html
https://dbaplus.cn/news-11-1267-1.html
https://dbaplus.cn/news-11-1138-1.html?utm_source=oschina-app