Home > Database > Mysql Tutorial > Examples to explain how to use crontab to back up MySQL regularly

Examples to explain how to use crontab to back up MySQL regularly

黄舟
Release: 2016-12-16 11:16:43
Original
1514 people have browsed it

Use the system crontab to execute backup files regularly and save the backup results by date to achieve the purpose of backup.


1. Create the path to save the backup file /MySQLdata


#mkdir /mysqldata


2. Create the /usr/sbin/bakmysql file


#vi /usr/sbin /bakmysql


Enter


Note: The ` symbol is the symbol above the TAB key, not the


to the left of ENTER. There must also be a space after the date. Drq = `date +%y%m%d's `Tar ZCVF/Mysqldata/Mysql $rq.tar.gz/var/lib/mysql


rq=` date +%Y%m%d `

mysqldump --all-databases -u root -p password> /mysqldata/mysql$rq.sql

/var/lib /mysql is the directory of your database files. For some users, it is /usr/local/mysql/data. It may be different for everyone. /mysqldata/ represents the directory where backup files are saved. Everyone can also choose this according to their own requirements. Do.

3. Modify the file attributes to make it executable

# chmod +x /usr/sbin/bakmysql

4. Modify /etc/crontab

#vi / etc/crontab

Add

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

means to perform backup at 3 o'clock every day

02 * * * * root /usr/sbin/bakmysql

Back up every second minute of every hour


5. Restart crond


# /etc/rc.d/init.d/crond restart


Finish.

So you can see such a file in /mysqldata every day

mysql20070929.tar.gz

Just download it directly.

The above is an example of how to use crontab to regularly back up MySQL. For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
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