How to set up scheduled backup database in MySQL
Today, I will talk to you about how to set up a regular backup database in MySQL. Many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.
1. View mysqldump
Root@laowang:/# which mysqldump/usr/bin/mysqldump
two。 Write a script
Edit the my.cnf file, specify the account number and password, and then reference it in the script
Root@laowang:/# vim / etc/ my.cnf[mysqldump] user=rootpassword=root
Script file
Root@laowang:/var/backups# vim mysqlbacks backup.shroud backup bins / bins # backup database # # mysqldump backup program executes path DUMP=/usr/bin/mysqldump# backup file storage path OUT_DIR=/var/database# backup file belongs to permissions LINUX_USER=root# database name to be backed up number of days DB_NAME=laowang# backup Before deleting DAYS=1#, enter the backup storage directory cd $OUT_DIR# to get the current system time DATE= `date +% yearly% masked% d` # backup database file name OUT_SQL=$DB_NAME "_ $DATE.sql" # finally saved database backup file name TAR_SQL=$DB_NAME "_ $DATE.tar.gz" # start backup database $DUMP-- defaults-extra-file=/etc/my.cnf-- default-character-set=utf8 $DB_NAME > $OUT_SQL# is compressed into .tar.gz format tar-czf $TAR_SQL. / $OUT_SQL# deletes backup files in .sql format rm $OUT_SQL# changes the owner of backup database files chown $LINUX_USER:$LINUX_USER $OUT_DIR/$TAR_SQL# deletes backup files 30 days ago (Note: {}\ ) find $OUT_DIR-name "* .tar.gz"-type f-mtime + $DAYS-exec rm-f {}\
3. Timed planning
Root@laowang:/# crontab-e # m h dom mon dow command10 10 * / var/backups/mysql_backup.sh
Ctrl+X exit
Y Save changes
After reading the above, do you have any further understanding of how to set up a scheduled backup database in MySQL? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.