Home > Article > Operation and Maintenance > How to automatically back up mysql database every day in Linux
/usr/bin is the mysql installation directory
Create a backup folder:
mkdir mysql_data_bak
Create a script file:
touch autobackupmysql.sh
Open the file
vi autobackupmysql.sh
Add the following content to the script:
filename=`date +%y%m%d` /usr/bin/mysqldump -opt mysql -u root -proot|gzip >/mysql_data_bak/name$filename.gz
Note here
General:
********************************************************** 打开自动执行文件 vi /etc/crontab 在etc中加入如下内容,让其自动执行任务。 01 15 * * * root /mysql_data_bak/autobackupmysql **********************************************************
redhat method:
redhat’s crontab Use 4 directories to be called by time (/etc/cron.hourly: every hour; /etc/cron.daily: every
day; /etc/cron.weekly: every week; /etc/cron.monthly: every month ) to run the script.
In redhat, you only need to copy the script you just edited to the corresponding directory.
cp /mysql_data_bak/autobackupmysql etc/cron.daily
Restart etc
/etc/rc.d/init.d/crond restart
The above is the detailed content of How to automatically back up mysql database every day in Linux. For more information, please follow other related articles on the PHP Chinese website!