What should be done to configure automatic backup of mysql database in centos
What should I do to configure automatic backup of mysql database in centos? Many people do not know much about it. Today, in order to let you know more about the method of configuring automatic backup of mysql database in centos, I have summarized the following contents. Let's look down together.
1. Check the disk space
Execute df-h to select the directory with the largest remaining space (take the / directory as an example)
2. Create a backup directory
Cd / mkdir backupcd backup
(related video tutorials share: mysql video tutorials)
3. Create a backup Shell script
Vim monarch-bak.sh # monarch is the database name mysqldump-uroot-p980225 monarch > / backup/monarch_$ (date +% Y-%m-%d_%H:%M:%S) .SQL # compress the backup: mysqldump-uusername-ppassword DatabaseName | gzip > / home/backup/DatabaseName_$ (date +% Y%m%d_%H%M%S) .sql.gz
4. Add executable permissions:
Chmod upright x monarch-bak.sh
Execute it after adding executable permissions to see if there are any errors in the script and whether it can be used normally:. / bkDatabaseName.sh
5. Add scheduled backup tasks
Confirm that crontab is installed.
Crontab-e
Add:
22 11 * source / backup/monarch-bak.sh # explain executing the / backup/monarch-bak.sh script at 11:22 every day
Restart crontab:
Service crond restart
The above is a brief introduction of how to configure automatic backup of mysql database in centos. Of course, the differences in the detailed use of the above have to be understood by everyone. If you want to know more, welcome to follow the industry information channel!