Simple backup of MySQL database operations

Source: Internet
Author: User

The following articles mainly introduce the simple backup of MySQL databases, including how to configure the corresponding backup directory code on the server and the actual operation steps of the backup script, and how to use crontab to regularly execute the backup script. Hope you will have some gains.

Simple backup MySQL database 1: configure the Backup Directory code on the server:

 
 
  1. mkdir /var/lib/MySQLbackup  
  2. cd /var/lib/MySQLbackup 

Simple backup MySQL database 2: backup script:

 
 
  1. vi dbbackup.sh 

Note: Change username, password, and dbname.

Enter the code:

 
 
  1. #!/bin/sh  
  2. #Username to access the MySQL server  
  3. USERNAME="username" 
  4. # Username to access the MySQL server  
  5. PASSWORD="password" 
  6. # List of DBNAMES for Backup  
  7. DBNAME="dbname" 
  8. #date timestamp for log message  
  9. DATE=`/bin/date +%Y-%m-%d_%Hh%Mm`  
  10. #output file  
  11. OUTDIR="/var/lib/MySQLbackup/" 
  12. OUTFILE="ip_bindass".$DATE."sql.gz"  
  13. #working directory  
  14. DIR="/var/lib/MySQLbackup/" 
  15. #cd $DIR  
  16. # MySQL Backup  
  17. /usr/bin/MySQLdump --database $DBNAME --opt --single-transaction   
  18. -u$USERNAME -p$PASSWORD | /usr/bin/gzip -9 > $OUTDIR$OUTFILE 

Change backup script permission

 
 
  1. chmod +x dbbackup.sh 

Simple backup MySQL database 3: Use crontab to regularly execute the backup script:

 
 
  1. crontab -e  

If you back up data at three o'clock P.M. every day, add the following code:

 
 
  1. 20 15 * * * /var/lib/MySQLbackup/dbbackup.sh  

The above content is an introduction to the simple backup of the MySQL database. I hope you will have some gains.

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.