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

CSS optimization skills self-practice experience

1. Use css sprites. The advantage is that the smal...

Learn the common methods and techniques in JS arrays and become a master

Table of contents splice() Method join() Method r...

Vue achieves seamless carousel effect (marquee)

This article example shares the specific code of ...

Example of how to configure the MySQL database timeout setting

Table of contents Preface 1. JDBC timeout setting...

Detailed explanation of fs module and Path module methods in Node.js

Overview: The filesystem module is a simple wrapp...

Two tools for splitting the screen in the Linux command line terminal

Here are two terminal split screen tools: screen ...

JS realizes automatic playback of timeline

Recently, I have implemented such an effect: clic...

Why TypeScript's Enum is problematic

Table of contents What happened? When to use Cont...

Detailed explanation of the integer data type tinyint in MySQL

Table of contents 1.1Tinyint Type Description 1.2...

Vue+Element realizes paging effect

This article example shares the specific code of ...

How to use resident nodes for layer management in CocosCreator

CocosCreator version: 2.3.4 Most games have layer...

Table td picture horizontally and vertically centered code

Html code: Copy code The code is as follows: <t...

Native js implementation of slider interval component

This article example shares the specific code of ...

MySQL uses frm files and ibd files to restore table data

Table of contents Introduction to frm files and i...