1. Create a shell script vim backupdb.sh Create the script as follows: #!/bin/sh db_user="root" db_passwd="123456" db_name="userdb" name="$(date +"%Y%m%d%H%M%S")" /usr/bin/mysqldump -u$db_user -p$db_passwd $db_name >>/home/backup/$name.sql illustrate: /usr/bin/mysqldump: the path of the mysqldump backup tool in the mysql database installation directory dbname: the name of the database to be backed up /home/backup/$name.sql: the backup file output location, which can be set according to the situation 2. Add execution permissions to the shell script chmod +x backupdb.sh 3. Add a scheduled task to the script crontab -e Enter the name of the previous line to edit the scheduled task, and finally add the following content 00 01 * * * /bin/sh /usr/local/mysql/backupdb.sh The above scheduled task means that the automatic backup script will be executed at 1:00 a.m. every day to perform a scheduled backup of the MySQL database. Description of crontab file: In the crontab file created by the user, each line represents a scheduled task, and each field in each line represents a setting. Its format is divided into six fields per line. The first five fields are time setting fields, and the sixth field is the command field to be executed. The format is as follows: minute hour day month week command Parameter Description: minute: represents the minute, which can be any integer from 0 to 59. Summarize The above is the scheduled backup of MySQL database introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: How to implement remote access control in Centos 7.4
>>: Three solutions for sub-functions accessing external variables in JavaScript
Text hiding code, hide a certain text in HTML Copy...
A MySQL custom value is a temporary container for...
Table of contents 1. Introduction 2. Customize ta...
In the previous chapters, we introduced how to ch...
First, let’s take a look at the picture: Today we...
To write a drop-down menu, click the button. The ...
When configuring nginx reverse proxy, the slashes...
Copy code The code is as follows: html { overflow...
Overview In a relational database, an index is a ...
1. Log in to MySQL and use SHOW VARIABLES LIKE ...
Preface I was recently reading about MySQL indexe...
Problem Description When we are working on a proj...
With the rise of mobile terminals such as iPad, p...
offset Offset is the offset. Using the offset ser...
1. Introduction to KVM The abbreviation of kernel...