Automatic Backup of MySQL database in window System

Source: Internet
Author: User
Tags mysql tutorial mysql backup

Use winrar to regularly back up the mysql tutorial database.
For mysql backup, the best way is to back up the data directory of the mysql database directly. The following provides a method for using winrar to regularly back up the data directory.
 

First, install winrar on the computer.

 

Write the following command into a text file

 

Net stop mysql

Del d: mysqldata/q

C: progra ~ 1 winrarwinrar a-ag-k-r-s d: mysql.rar d: mysqldata

Net start mysql

 

Save and modify the extension of the text file to cmd.
Go to the control panel, open the scheduled task, and double-click "add scheduled task ". In the scheduled task wizard, find the cmd file and specify a running time and the account and password used for the task.

The following hypothetical environment:

Mysql installation path: c: mysql
Forum Database Name: bbs
Database Backup destination: c: db_bak
======================================
Create db_bak.bat and write the following code

 

 

[Copy to clipboard] code:
Net stop mysql
Xcopy c: mysqldatabbs *. * c: db_bakbbs % date :~ 0, 3%/y
Net start mysql

Then run the batch processing script periodically using windows's scheduled task. (For example, execute back_db.bat at every day)
Explanation: backup and recovery operations are relatively simple, with high integrity and Flexible backup cycle control. For example, to save data for one week, use % date :~ 0, 3%, save the daily data, with % date :~ 4,10%. This method is suitable for users who have independent hosts but have no management experience on mysql. The disadvantage is that the database occupies a large amount of space and mysql will be disconnected for a short time during Backup (for example, it takes about 5 seconds for a database of about 30 mb ).


====================
Hypothetical environment:
Mysql installation path: c: mysql
Forum Database Name: bbs
Mysql root Password 123456
Database Backup destination: d: db_backup

Script:

 

[Copy to clipboard] code:
@ Echo off
C: mysqlbinmysqladmin-u root -- password = 123456 shutdown
C: mysqlbinmysqldump -- opt-u root -- password = 123456 bbs> d: db_backupbbs. SQL
C: mysqlbinmysqld-nt

Save the preceding code as backup_db.bat.
Then, run the script periodically using the "scheduled task" of windows. (For example, execute back_db.bat at every day)

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.