Simple Mysql backup BAT script sharing under Windows

Simple Mysql backup BAT script sharing under Windows

Preface

This article introduces a simple BAT script for backing up Mysql in Windows. The script uses the mysqldump command to back up a specified Mysql database to a file in the format of %dbname%-yyyyMMddHHmmss.sql . Only the backups of the last 60 days are retained. If you want to execute it at a scheduled time, 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"

Summarize

The above is the full content of this article. I hope that the content of this article can bring some help to your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Using bat script to upload and download ftp regularly under windows
  • How to remove the small arrow in the shortcut in Windows 7? BAT script sharing
  • Windows sets up a bat script to start automatically at boot time
  • Detailed explanation of for loop usage in Windows bat script

<<:  Example of implementing circular progress bar in Vue

>>:  A complete list of common Linux system commands for beginners

Recommend

Detailed discussion of the character order of mysql order by in (recommended)

//MySQL statement SELECT * FROM `MyTable` WHERE `...

Detailed explanation of three ways to connect Docker containers to each other

There are three ways to interconnect and communic...

Solve the problem of black screen when starting VMware virtual machine

# Adjust VMware hard disk boot priority Step 1: E...

How to deploy Vue project under nginx

Today I will use the server nginx, and I also nee...

Implementing a web calculator with native JavaScript

This article shares the specific code of JavaScri...

Docker installs Elasticsearch7.6 cluster and sets password

Starting from Elasticsearch 6.8, free users are a...

Implementation of local migration of docker images

I've been learning Docker recently, and I oft...

Docker file storage path, modify port mapping operation mode

How to get the container startup command The cont...

JavaScript Composition and Inheritance Explained

Table of contents 1. Introduction 2. Prototype ch...

How to find and delete duplicate rows in MySQL

Table of contents 1. How to find duplicate rows 2...

How to manually install MySQL 5.7 on CentOS 7.4

MySQL database is widely used, especially for JAV...

Vue Element front-end application development to obtain back-end data

Table of contents Overview 1. Acquisition and pro...

js to write the carousel effect

This article shares the specific code of js to ac...

This article will show you how JavaScript garbage collection works

Table of contents 1. Overview 2. Memory Managemen...