Perfect interpretation of automatic MySQL backup in Linux

Source: Internet
Author: User

We often back up some data in our work to prevent important data loss. If you are using a Linux operating system, how can you better use this document? This article explains how to automatically back up MySQL Databases in Linux.

Regular MySQL backup is an important task, but manual operations are too cumbersome and difficult to avoid any omissions. You can use the following method to regularly back up data.
1. Create a backup folder
# Cd/www
# Makedir backup

2. Write a running script
# Vi autobackup

Write the following content:
Filename = 'date + % Y % m % d' mysql _ bin_dir/mysqldump-opt dataname-u user-ppassword | gzip>/www/mysqlbackup/name1_filename.gz

Save and exit

Note:

(1) mysql_bin_dir: bin path of mysql;

(2) dataname: Database Name;

(3) user: Database user Name;

(4) password: User password;

(5) name: ID of the prefix of the backup file.

In this example, the MySQLDatabase is automatically created and stored in gzipcompressed format. The file name is name20080101.gz.

3. Add execution permissions for the script
# Chmod + x autobackup

4. Let crontab complete the task of regular execution

In this step, the Redhat method will be different and will be provided later.

Edit crontab:
# Vi/etc/crontab

Add the following to the last line:
01 5 *** root/www/autobackup

Run the script at every day, or change 5 to another specified time.

Redhat method:

Redhat crontab uses time to call four directories/etc/cron. hourly: hourly;/etc/cron. daily: daily;/etc/cron. weekly: weekly;/etc/cron. monthly: indicates how the script runs every month.

In Redhat, you only need to copy the edited script to the corresponding directory.

5. Restart crontab
#/Etc/rc. d/init. d/crond restart

Complete automatic MySQL backup to easily apply Linux.

  1. Operation notes: Linux system backup tar Compression
  2. A promising Linux operating system
  3. Getting Started: Install vmware on GNU/Linux
  4. Comment on the advantages and disadvantages of Linux releases
  5. The perfect QT comes from the linux operating system

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.