How to automatically backup Mysql under Linux _mysql

Source: Internet
Author: User

Linux can use the crontab system to regularly back up the MySQL database every day, the following are detailed steps:

1, create the path to save the backup file/mysqldata

#mkdir/mysqldata

2. Create/usr/sbin/bakmysql files

#vi/usr/sbin/bakmysql

Input

rq= ' Date +%y%m%d '

Tar Zcvf/mysqldata/mysql$rq.tar.gz/var/lib/mysql

or write

rq= ' Date +%y%m%d '

Mysqldump–all-databases-u root-p980405 >/mysqldata/mysql$rq.tar.gz

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

/mysqldata/represents the directory where the backup files are saved, and everyone can do it according to their own requirements.

3, modify the file properties to make it executable

# chmod +x/usr/sbin/bakmysql

4. Modify/etc/crontab

#vi/etc/crontab

Add the following

3 * * * root/usr/sbin/bakmysql

Indicates a backup is performed 3 o'clock daily

5. Reboot Crond

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

Complete.

So every day you can see a file like this in/mysqldata.

Mysql20100101.tar.gz

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.