Backup script:
#!/bin/bashdate_str=$(date +%Y%m%d-%T)cd /bf/mysql_back mysqldump -h localhost -u root --password=PASSWORD -R -E -e \databaseName \ | gzip > /bf/mysql_back/database_$date_str.sql.gz
Use crontab to execute the above script regularly
crontab -e
Perform backup every Monday morning
05 02 * * 1 /home/mysqls_backup/mysqlbackup.sh
View crontab list
crontab -l
Effective immediately
/etc/init.d/cron restart
The above is the detailed content of How to write a script for mysql scheduled backup in Linux. For more information, please follow other related articles on the PHP Chinese website!