How to automatically back up mysql database every day in Linux

PHPz
Release: 2023-05-18 13:14:11
forward
868 people have browsed it

/usr/bin is the mysql installation directory
Create a backup folder:

mkdir mysql_data_bak
Copy after login

Create a script file:

touch autobackupmysql.sh
Copy after login

Open the file

vi autobackupmysql.sh
Copy after login

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
Copy after login

Note here
General:

**********************************************************
打开自动执行文件
vi /etc/crontab
在etc中加入如下内容,让其自动执行任务。
01 15 * * * root /mysql_data_bak/autobackupmysql
**********************************************************
Copy after login

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
Copy after login

Restart etc

/etc/rc.d/init.d/crond restart
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!