Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the method of using crontab to back up Mysql database regularly in Linux system

Shulou Source: shulou.com Published: 2022-06-03 10:30:41 11月15日 Update

Linux system using crontab regular backup Mysql database method is how, I believe many inexperienced people are helpless, for this reason this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

The system crontab is used to execute backup files regularly, and the backup results are saved according to the date to achieve the purpose of backup.

1. Create a path to save backup files/mysqldata#mkdir /mysqldata2. Create a file/usr/sbin/bakmysql #vi /usr/sbin/bakmysql

input

rq= date +%Y%m%dtar zcvf /mysqldata/mysql$rq.tar.gz /var/lib/mysql

Or write

rq= date +%Y%m%dmysqldump -all-databases -u root -p cipher> /mysqldata/mysql$rq.sql

/var/lib/mysql is the directory of your database files, some users are/usr/local/mysql/data, everyone may be different

/mysqldata/indicates the directory where backup files are saved, which everyone can do according to their own requirements.

3. Modify the file attributes so that it can execute # chmod +x /usr/sbin/bakmysql4. Modify/etc/crontab#vi /etc/crontab

Add below

01 3 * * * root /usr/sbin/bakmysql

means backup is performed at 3 o'clock every day

The requested URL/etc/rc.d/was not found on this server.

Done.

So every day you can see this file in/mysqldata

mysql20040619.tar.gz

You can download it directly.

After reading the above, do you know how to use crontab to backup Mysql database regularly in Linux system? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!

Tags: Backup file method data database system content more directory problem different helpless for this reason password this attribute skill date user Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux OPPO Reno MySQL vpn Huawei