BAT file backup MySQL database

Source: Internet
Author: User

1. Copy the date folder backup
======================================
Hypothetical environment:
MySQL installation path: C:/program files/MySQL Server 5.0
Forum Database Name: Attendance
Database Backup destination: D:/test/attendance/
======================================
Create db_bak.bat and write the followingCode

* ******* Start the BAT file code **********

Net stop MySQL

Xcopy "C:/program files/MySQL Server 5.0/data/attendance/*. *" D:/test/attendance/% Date :~ 0, 10%/S/I

Net start MySQL

@ Echo off
Echo execution ended over
Set/P skysnow =
Echo % skysnow %

 

* ******* BAT file code ended **********

 

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 usage of %, 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/mysqldump" -- opt-u root -- Password = 123456 BBS> D:/db_backup/BBS. SQL

* ***************************** 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)

"start" → "attachment" → " System Tools ">" task plan "(requires the computer password)

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.