Methods for automatic MySql backup in Windows

Source: Internet
Author: User
Tags mysql backup

1. Copy the date folder backup
======================================
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


* ***************************** Code Start ******* **********************
Net stop mysql
Xcopy c: \ mysql \ data \ bbs \ *. * c: \ db_bak \ bbs \ % date :~ 0, 10% \/S/I
Net start mysql
* ***************************** Code End ******* **********************

Then run the batch processing script periodically using Windows's scheduled task. (For example, execute back_db.bat at every day)
Explanation: the backup and recovery operations are simple, the integrity is relatively high, and the backup cycle is controlled flexibly. For example, % date :~ 0, 10%. This method is suitable for users who have independent hosts but have no management experience on mysql. The disadvantage is that it takes a lot of space and mysql will be disconnected for a short time during the backup period (for example, it takes about 5 seconds for a database of about 30 mb), for % date :~ For more information, see.


2. Back up mysqldump to an SQL File
====================
Hypothetical environment:
MySQL installation path: C: \ MySQL
Forum Database Name: bbs
MySQL root Password 123456
Database Backup destination: D: \ db_backup \

Script:


* ***************************** Code Start ******* **********************
@ Echo off
C: \ MySQL \ bin \ mysqladmin-u root -- password = 123456 shutdown
C: \ MySQL \ bin \ mysqldump -- opt-u root -- password = 123456 bbs> D: \ db_backup \ bbs. SQL
C: \ MySQL \ bin \ mysqld-nt
* ***************************** Code End ******* **********************

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)


3. Use WinRAR to regularly back up MySQL databases. 
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

* ***************************** Code Start ******* **********************
Net stop mysql

C: \ progra ~ 1 \ winrar a-ag-k-r-s d: \ mysql.rar d: \ mysql \ data

Net start mysql
* ***************************** Code End ******* **********************

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 disadvantage of this method is that it takes a lot of time to compress the data during the backup. mysql disconnection takes more time than the first method, but the file name is good. In short, each has its own merits.

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.