MySQL automatic backup script in Linux

Source: Internet
Author: User
Tags chmod mysql automatic backup

In fact, the MySQL automatic backup of the small script is very simple, the following is the steps of this small script.

The code is as follows Copy Code
#cd/www
#mkdir Mysqlbackup
#vi mysqlautobackup.sh

This mysqlautobackup.sh file is written in the following sections:

The code is as follows Copy Code
Filename= ' Date +%y%m%d '
Mysql_bin_dir/mysqldump--opt datename-u Dateuser-pdatepassword | gzip >/www/mysqlbackup/datename$filename.gz

Save the exit, and then give the file the executable permission:

The code is as follows Copy Code
#chmod 777 mysqlautobackup.sh

Then edit crontab:

The code is as follows Copy Code
#vi/etc/crontab

On the last line, add the following:

The code is as follows Copy Code
5 * * * root/www/mysqlautobackup.sh

and restart the crontab:

The code is as follows Copy Code
#/etc/rc.d/init.d/crond Restart

This is done, and every day in the morning 5 points will automatically perform a MySQL automatic backup command.

Note: Mysql_bin_dir refers to MySQL's bin path. Datename refers to the database name. Dateuser refers to the database user name. Datepassword refers to the database user password.

This is the Linux under the implementation of automatic backup of MySQL tips, is it easy?

Pay attention.

Note:

MySQL is running as a MySQL user and will fail to write to/home/mybackup

chmod 777/home/mybackup

This is a privilege issue in Linux, and you don't have to think about it if you can successfully back it up.

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.