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
1. Basic implementation of limit In general, the ...
Table of contents Preface Preliminary preparation...
The situation is as follows: (PS: The red box repr...
Before the arrow was shot, the bow whispered to t...
Preface I believe many students are already famil...
The principle of nginx to achieve resource compre...
I have been taking a lot of MySQL notes recently,...
01. Command Overview Linux provides a rich help m...
The display effects on IE, Fir...
Library Management Create a library create databa...
MySQL Create Database After logging into the MySQ...
The form code is as shown in the figure. The styl...
Recently, I need to query all the fields in a rel...
Does color influence website visitors? A few year...
Reproduce on Kali First set suid permissions for ...