Batch command bat back up MySQL database

Source: Internet
Author: User
Tags rar

Batch command bat back up MySQL database

Font: [Increase decrease] Type: Reprint time: 2009-07-23 I want to comment

There may be a lot of backup tools for MySQL data, and here I'm going to share it with DOS batch commands and MySQL, winrar commands for backup work. Working Environment Windows Server 2003, MySQL installation directory D:\MySQL, WinRAR installation directory C:\Program Files\winrar\winrar.exe
The path to the backup data store is a e:\ data backup, so start writing DOS batch commands below.
Copy CodeThe code is as follows:
Set "ymd=%date:~,4%%date:~5,2%%date:~8,2%"
MD "E:\ data backup \%ymd%"
"D:\MySQL\bin\mysqldump.exe"--opt-q mysql-uroot-p123456789 > E:\ Data Backup \%ymd%\mysql.sql
Rem..... Here you can add more commands, depends on how many databases you have, where-Q is followed by the database name-p followed by the password
echo Winrar Loading ...
"C:\Program files\winrar\winrar.exe" a-ep1-r-o+-m5-df "e:\ data backup \%ymd%.rar" "E:\ Data Backup \%ymd%"
Echo ok!
Save the above command as Backup.bat, double-click to run and start backing up the data.
The first sentence is to create a variable%ymd%, by%date% the system variable to get the date,%date:~,4% represents the date of the preceding 4 characters is the year,%%date:~5,2% that the date of the 5th character to start the 2 characters is the month,%date:~8,2% This is the date, as in 2009-06-20, the result of this date was 20090620.
The second sentence is to use the value of the variable%ymd% to create an empty folder.
The third sentence starts with the MySQL command to backup the database MySQL, and stored in the E:\ data backup \%ymd% This folder, here can have a lot of similar commands, backup multiple databases.
The end is to use WinRAR to compress the backed up data and store it as a RAR file name built with the%ymd% variable value, while deleting the backup%ymd% directory.
If you want the system to be automatically scheduled for regular backups, you can perform this command periodically through the system's task schedule.

Batch command bat back up MySQL database

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.