This article is a mirror article of machine translation, please click here to jump to the original article.

View: 33559|Reply: 1

[Source] Use MySQL to automatically schedule backups in a Windows environment

[Copy link]
Posted on 4/12/2019 11:46:40 AM | | | |
1. Write a backup script

This is a very common Windows batch script file, and I will briefly explain the key parts:

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 that start with "backup_" and are suffixed with ".sql". The number "30" after indicates that the 30-day expiration date.

Use the set command to define a variable called "Ymd", and the value of this variable is a large set of rules, simply put, the current date and time
This line of command is to call the backup tool that comes with MySQL, note that this path must be written as the path where your own "mysqldump.exe" is located, usually in the /bin directory of the MySQL installation path. This line of command is followed by a large list of parameters, let's pick a few important ones to explain:

Accounts connected to the MySQL database service must have permission to perform database backup operations. For the sake of simplicity, we use root, but it is not recommended to use root accounts in the actual production environment to avoid account and password leakage, which will cause unnecessary trouble.
This is the password to connect to the MySQL database service
This is the IP address of the server where the database service is located
This is the port number of the server where the database service is located
events parameter to back up the database to a specified file. "yumi_website" is the database that needs to be backed up, and the right side of the sign ">" is the server directory and file name where our backup file is stored.

2. Set Windows tasks

Once we have completed the above steps, we need to add the Windows scheduled task.

In Windows Server 2008, we go to the server management panel, click "Tools" in the upper right menu bar, and select "Task Scheduler" in it:




After opening the task scheduler, we click on "Create basic task" on the right:



Then, we need to fill in the name of the task, as well as the description information:



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



Click "Next" again, set the time for the task execution, I chose 1 o'clock in the dead of night:



In "Next" we select "Launch program":



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



Once these steps are completed, Windows will give us an overview of the entire task:



Once you're sure, click "Done". At this point, we will see that there is a new task in the Windows task list:



At this point, the automatic backup of MySQL in the Windows environment is all set.




Previous:Java determines whether a class inherits a parent class
Next:asp.net GridView dynamically generates columns
 Landlord| Posted on 9/30/2021 11:30:51 AM |
CMD bat standardizes several methods to obtain the current system date, and adds 0
https://www.itsvse.com/thread-9673-1-1.html
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com