Implementation of MySQL scheduled backup script under Windows

Implementation of MySQL scheduled backup script under Windows

On a Windows server, if you want to back up database data on a regular basis, you can use the Windows Task Scheduler + database backup script combination. Among them, mysqldump plays a key role in MySQL database backup. For information about the usage of the mysqldump command, you can find the official documentation of MySQL.

1 Backup Script

@echo off

echo Set the connection information of MySql database set host=127.0.0.1
set port=3306
set user=root
set pass=admin

echo Set the name of the MySql database to be backed up set dbname=test

echo gets the date format of the day, for example: 20200902231300
set hour=%time:~0,2%
if "%time:~0,1%"==" " set hour=0%time:~1,1%

set backup_date=%Date:~0,4%%Date:~5,2%%Date:~8,2%%hour%%Time:~3,2%%Time:~6,2%

echo Set the path of the backup file set backupfile=D:\mysql\beifen\%dbname%-%backup_date%.sql


echo Use mysqldump to back up the specified MySql echo Note that if there is a space in the path, add double quotes "C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqldump" -h%host% -P%port% -u%user% -p%pass% -c --add-drop-table %dbname% > %backupfile%

echo delete expired files, here it is deleted after more than 30 days forfiles /p D:\mysql\beifen /s /m *.sql /d -30 /c "cmd /c del @file /f"

2 Backup Success Screenshot

Method 2: Mysql automatic backup script under Windows

:: The MySQL version used when writing the script is mysql5.5.16 Ver 14.14 Distrib 5.5.16, for Win32 (x86)
:: This script is used to save a database:: Configure script parameters:: Configure database user SET DB_USER=root

:: Configure database password SET DB_PASSWORD=yuanse3366

:: Configure the backup database name SET DB_NAME=soms

:: Configure the backup file path SET SAVE_PATH=D:\databack\data

:: Configure the path of mysqldump SET MYSQL_DUMP_PATH=D:\wamp\mysql\bin\mysqldump.exe

:: Start working:: Jump to the working directory %SAVE_PATH:~0,2%
cd %SAVE_PATH%
:: Set variable: backup file name SET BAK_FILE=%SAVE_PATH%\soms_bak_%date:~0,4%_%date:~5,2%_%date:~8,2%_%time:~0,2%_%time:~3,2%.sql
:: Start backup %MYSQL_DUMP_PATH% -u%DB_USER% -p%DB_PASSWORD% %DB_NAME% --lock-all-tables -r%BAK_FILE%

Copy the above script and save it as a BAT file, modify the configuration parameters, and then add it to the Windows scheduled task.

This is the end of this article about the implementation of MySQL scheduled backup script under Windows. For more relevant MySQL scheduled backup script content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

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
  • The best way to automatically backup the mysql database (windows server)
  • Using MySQL in Windows: Implementing Automatic Scheduled Backups

<<:  Web page creation question: Image file path

>>:  js tag syntax usage details

Recommend

JS implements simple calendar effect

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

Example of Html shielding right-click menu and left-click typing function

Disable right-click menu <body oncontextmenu=s...

Summary of MySQL string interception related functions

This article introduces MySQL string interception...

Implementation of Nginx configuration https

Table of contents 1: Prepare https certificate 2:...

Several ways to remove the dotted box that appears when clicking a link

Here are a few ways to remove it: Add the link dir...

Node implements search box for fuzzy query

This article example shares the specific code for...

Docker realizes the connection with the same IP network segment

Recently, I solved the problem of Docker and the ...

Vue.js implements tab switching and color change operation explanation

When implementing this function, the method I bor...

Implementing calculator functions with WeChat applet

This article is a simple calculator written using...

javascript countdown prompt box

This article example shares the specific code of ...

Make a nice flip login and registration interface based on html+css

Make a nice flip login and registration interface...

Can MySQL's repeatable read level solve phantom reads?

introduction When I was learning more about datab...

MySQL 8.0.17 installation and usage tutorial diagram

Written in front In the past and in the current p...

Tutorial analysis of quick installation of mysql5.7 based on centos7

one. wget https://dev.mysql.com/get/mysql57-commu...