A practical method for Linux to automatically back up MySQL database

Source: Internet
Author: User
Tags add execution mysql mysql database backup linux

MySQL regular backup is an important work, but manual operation is too cumbersome, also difficult to avoid omissions, use the following methods to allow the system to back up data on a regular basis.
1. Create a backup folder

#cd/www

#makedir Backup

2. Write Run script

#vi Autobackup

Write the following:

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

mysql_bin_dir/mysqldump–opt dataname-u User-ppassword gzip >/www/mysqlbackup/name$filename.gz

Save exit

Description

(1) The bin path of the Mysql_bin_dir:mysql;

(2) Dataname: database name;

(3) User: Database username;

(4) Password: User password;

(5) Name: Custom backup file prefix identification.

As in the previous example, the MySQL database is automatically backed up and stored in gzip compression, in the form of a file named name20080101.gz.

3. Add execution permissions to the script

#chmod +x Autobackup

4, let crontab to complete the task of regular execution

In this step, the Redhat method will be different, specifically given in the following.

Edit crontab:

#vi/etc/crontab

In the last line, add:

5 * * * root/www/autobackup

Run the script at 5 o ' Day, or you can modify 5 for another specified time.

Redhat Method:

Redhat crontab 4 directories per hour (/etc/cron.hourly: hourly;/etc/cron.daily: per day;/etc/cron.weekly: Weekly;/etc/cron.monthly: Monthly) The way the script comes out to run.

In Redhat, just copy the script you just edited to the appropriate directory.

5, restart Crontab

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

Complete.



Related Article

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.