Using MySQL in Windows: Implementing Automatic Scheduled Backups

Using MySQL in Windows: Implementing Automatic Scheduled Backups

1. Write a backup script

rem auther:www.yumi-info.com
rem date:20171222
rem ******MySQL backup start********
@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
rem ******MySQL backup end********

This is a very common Windows batch script file. Let me briefly explain the key parts:

forfiles /p "E:\mysql\MySQL BackUp" /m backup_*.sql -d -30 /c "cmd /c del /f @path"

forfiles is used to delete expired backups in the backup directory. "E:\mysql\MySQL BackUp" is the path where the backup file is located, which can be modified by yourself. "backup_*.sql" refers to all database backup files in this path that start with "backup_" and end with ".sql". The number "30" at the end means it will expire in 30 days.

set "Ymd=%date:~0,4%%date:~5,2%%date:~8,2%0%time:~1,1%%time:~3,2%%time:~6,2%"

Use the set command to define a variable named "Ymd". The value of this variable is the following string of rules, which is simply the current date and time.

"E:\mysql\MySQL Server 5.6\bin\mysqldump"

This line of command calls the backup tool that comes with MySQL. Note that this path must be written as the path where your own "mysqldump.exe" is located, which is usually in the /bin directory of the MySQL installation path. This command line is followed by a long list of parameters. Let's pick out a few important ones to explain:

--user=root

The account used to connect to the MySQL database service. Usually, this account must have the permission to perform database backup operations. For the sake of simplicity, we used root, but it is not recommended to use the root account in an actual production environment to avoid account and password leakage, which would cause unnecessary trouble.

--password=123456

This is the password to connect to the MySQL database service

--host=127.0.0.1

This is the IP address of the server where the database service is located

--port=3306

This is the port number of the server where the database service is located

--events "yumi_website" > "E:\mysql\MySQL BackUp\backup_%Ymd%.sql"

The events parameter implements the operation of backing up the database to a specified file. "yumi_website" is the database that needs to be backed up, and the part to the right of the greater than sign ">" is the server directory and file name where our backup file is saved.

2. Set up Windows tasks

After completing the above steps, we need to add a Windows scheduled task.

In Windows Server 2012, we enter the server management panel, click "Tools" in the upper right menu bar, and select "Task Scheduler":

After opening the Task Scheduler, we click "Create Basic Task" on the right:

Then, we need to fill in the name of the task and description:

After clicking Next, we need to set the frequency of task execution. I chose "Daily":

Click "Next" again and set the time for the task to be executed. I chose 1 o'clock in the middle of the night:

In "Next", we select "Start a program":

In the subsequent dialog box, we need to select the batch file we just wrote:

After completing these steps, Windows will give us an overview of the entire task:

After confirming that everything is correct, click "Finish". At this point we will see a new task in the Windows task list:

At this point, the settings for automatic MySQL backup in Windows environment are complete.

The above article "Using MySQL in Windows environment: Implementing automatic scheduled backup" is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Shell script to implement mysql scheduled backup, deletion and recovery functions
  • Sharing of mysql scheduled backup Shell script under CentOS
  • MySQL scheduled backup solution (using Linux crontab)
  • Brief analysis of mysql scheduled backup tasks
  • MySQL scheduled database backup operation example
  • How to implement scheduled backup of MySQL database
  • How to backup MySQL regularly and upload it to Qiniu
  • A simple method to implement scheduled backup of MySQL database in Linux
  • Linux implements automatic and scheduled backup of MySQL database every day
  • Mysql database scheduled backup script sharing
  • Implementation of MySQL scheduled backup script under Windows
  • The best way to automatically backup the mysql database (windows server)

<<:  Methods for backing up Windows server files locally, Windows server data backup solutions

>>:  File backup solution between servers, how to automatically back up server files to another server?

Recommend

MySQL 5.7.21 installation and configuration tutorial

The simple installation configuration of mysql5.7...

Linux sar command usage and code example analysis

1. CPU utilization sar -p (view all day) sar -u 1...

How to change $ to # in Linux

In this system, the # sign represents the root us...

Vue realizes dynamic progress bar effect

This article example shares the specific code of ...

Example of setting up a whitelist in Nginx using the geo module

Original configuration: http { ...... limit_conn_...

Detailed tutorial on deploying Springboot or Nginx using Kubernetes

1 Introduction After "Maven deploys Springbo...

How to install redis5.0.3 in docker

1. Pull the official 5.0.3 image [root@localhost ...

Common solutions for Mysql read-write separation expiration

The pitfalls of MySQL read-write separation The m...

A solution to a bug in IE6 with jquery-multiselect

When using jquery-multiselect (a control that tra...

Simple CSS text animation effect

Achieve results Implementation Code html <div ...

VMware ESXi installation and use record (with download)

Table of contents 1. Install ESXi 2. Set up ESXi ...

vue+springboot realizes login function

This article example shares the specific code of ...