MySQL supports regular backup using MySQL administrator in windows, which is troublesome in Linux, if there is no ready-made product, you can only write it by yourself.
1. Create a MySQL. Sh file and enter
! /Bin/sh
# backup MySQL database
# delete file
Find/usr/local/backup/MySQL-type F-mtime + 7 -exec RM {}\;
RQ = 'date + % Y % m % d % H % m'
# backup each database
for dB in 'echo "show databases "|/usr/local/MySQL/bin/MySQL-uroot-p654123 | grep-V database ';
DO
echo $ dB;
/usr/local/MySQL/bin/mysqldump-Q-a-c-uroot-pxxxx $ db | gzip> 'echo "/usr/local/backup/MySQL/ other_db ($ Db1__1_rq. SQL .gz "'
done
The general idea is to delete the backup file seven days ago to avoid occupying too much hard disk space and then traverse all databases, backup files one by one. The backup files are compressed to save space.
modify the directory name and password in the file as needed.
2. Modify the file attributes so that they can be executed.
# chmod + x MySQL. sh
3. If you manually execute the file, the backup can be completed. However, our goal is to enable the system to automatically back up the file regularly, therefore, you also need to use the Linux Crontab function.
# vi/etc/crontab
Add
01 3 *** root/usr/sbin/MySQL. sh
indicates that the backup is performed at three o'clock every day. Modify the file name
4. Restart crond
#/etc/rc. d/init. d/crond restart
. You can view the backup file in the Backup Directory every day.