Home > Database > Mysql Tutorial > body text

Simple Mysql backup BAT script code sharing under Windows

黄舟
Release: 2017-03-16 13:45:52
Original
1779 people have browsed it

My friend said that the backup using the bat command under Windows failed. He couldn't find the problem for a while, so he asked me to help check it out. After searching, I solved the problem and wanted to summarize it, so this article mainly shares with you a simple Mysql backup BAT script under Windows. Friends who need it can refer to it.

Preface

This article introduces a simple BAT script to back up Mysql under Windows. The script uses mysqldump Command to back up a specified Mysql database to a file. The file format is %dbname%-yyyyMMddHHmmss.sql. Only the backups of the last 60 days are retained. If you want to execute it regularly, just add a task schedule in Windows. For details, please refer to this article.

The sample code is as follows


@echo off
set hour=%time:~0,2%
if "%time:~0,1%"==" " set hour=0%time:~1,1%
set now=%Date:~0,4%%Date:~5,2%%Date:~8,2%%hour%%Time:~3,2%%Time:~6,2%
echo %now%
set host=xxx.xxx.xxx.xxx
set port=3306
set user=root
set pass=root
set dbname=dataname
set backupfile=E:\backup\db\%dbname%-%now%.sql
E:\backup\mysql-5.7.13-winx64\bin\mysqldump -h%host% -P%port% -u%user% -p%pass% -c --add-drop-table %dbname% > %backupfile%
echo delete files before 60 days
forfiles /p "E:\backup\db" /m *.sql /d -60 /c "cmd /c del @file /f"
Copy after login

Summary

The above is the detailed content of Simple Mysql backup BAT script code sharing under Windows. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template