Automatic backup method of MySQL database in Window System

Source: Internet
Author: User
Tags mysql tutorial mysql backup

Use WinRAR to perform a scheduled backup of the MySQL Tutorial database tutorial.
For MySQL backup, the best way is to directly back up the MySQL database data directory. A method of using WinRAR to perform a scheduled backup of the data directory is provided below.

First of all, of course, install the WinRAR on the computer.

Write the following command to a text file

net stop MySQL

Del d:mysqldata/q

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

net start MySQL

Save, and then modify the extension of the text file to cmd.
Enter the control Panel, open the Scheduled task, and double-click Add Scheduled task. In the Scheduled Task Wizard, locate the cmd file just now, and then specify a run-time and run-time account password for this task.

The following hypothetical environment:

MySQL Installation location: c:mysql
Forum database name: BBS
Database backup destinations: C:db_bak
============================
Create a new 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

You can then use Windows Scheduled Tasks to execute the batch script at timed intervals. (For example: Perform Back_db.bat 3 o'clock in the morning every day)
Explanation: Backup and restore operations are relatively simple, integrity is relatively high, control backup cycle is more flexible, for example, save a week of data, with%date:~0,3%, save the daily data, with%date:~4,10%. This method is suitable for users who have a standalone host but have no management experience with MySQL. The disadvantage is that a lot of space, the backup period MySQL will be a short time to disconnect (for example: about 30m of the database takes about 5s).


==============
Hypothetical environment:
MySQL Installation location: c:mysql
Forum database name: BBS
MySQL root password: 123456
Database backup destinations: 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 above code as Backup_db.bat
You can then use Windows Scheduled Tasks to execute the script at timed intervals. (For example: Perform Back_db.bat 5 o'clock in the morning 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.