Mysql5.6数据库备份(windows)
1.配置备份脚本
把创建文件并保存为:mysql_bak.bat,把下面红字内容拷贝到此文件中并修改配置保存。
############################################################
@echo off
set hour=%time:~0,2%
if "%time:~0,1%"==" " set hour=0%time:~1,1%
setnow=%Date:~0,4%%Date:~5,2%%Date:~8,2%%hour%%Time:~3,2%%Time:~6,2%
echo %now%
::配置目标数据库地址、端口号、用户、密码、数据库
set host=192.168.106.179
set port=3306
set user=root
set pass=root
set dbname=jeeweb_mybatis
::配置备份路径、备份数据存留多长时间、本地备份命令位置
set bakPath=D:\MySQLdata_Bak
set delAgoDay=1
set localMysqlPath=D:\software\database\mysql-5.6.40-winx64
set backupfile=%bakPath%\%dbname%-%now%.sql
%localMysqlPath%\bin\mysqldump -h%host% -P%port% -u%user% -p%pass%-c --add-drop-table %dbname% > %backupfile%
echo delete files before %delAgoDay% days
forfiles /p "%bakPath%" /m %dbname%-*.sql -d -%delAgoDay%/c "cmd /c del @file /f"
ping /n 3 127.0.0.1 > nul
exit
############################################################
2.设置定时任务
1) 打开任务计划程序
2) 点击创建任务
3) 设置任务
确定即可成功。