Use mysqldump in Linux to regularly back up MySQL Databases

Source: Internet
Author: User

In Linux, use mysqldump to regularly back up MySQL databases:

  1. #! /Bin/bash
  2. PATH =/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin :~ /Bin
  3. Export PATH
  4. Export LANG = en_US.UTF-8
  5. Savedir =/log/database_bak/
  6. Cd"$ Savedir"
  7. Time ="$ (Date +"% Y-% m-% d % H: % M: % S")"
  8. Mysqldump-u [my_user]-p [my_pwd] [db_name]> [db_name]-"$ Time". SQL

Note that [my_pwd] is directly added without spaces after-p below.

Then, place the sh script in the/log/sh/directory and grant the execution permission. Finally, enter the linux scheduled task crond and add the following script:

  1. # Run-parts daily5Point02Sub-execution databasebak. sh
  2. 01* *** Root run-parts/etc/cron. hourly
  3. 02 4* ** Root run-parts/etc/cron. daily
  4. 22 4**0Root run-parts/etc/cron. weekly
  5. 42 4 1** Root run-parts/etc/cron. monthly
  6. 02 5* ** Root sh/log/sh/databasebak. sh

After saving the information, restart crond and service crond restart!

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.