Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set up scheduled backup database in MySQL

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report