Batchcompute command BAT to back up MySQL database

Source: Internet
Author: User

Working environment Windows Server 2003, MySQL Installation Directory D: \ MySQL, WinRAR installation directory C: \ Program Files \ WinRAR \ WinRAR.exe
The path of the backup data storage is E: \ data backup. After the backup data is ready, write the DOS batch processing command. 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... you can add more commands here, depending 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 \ policymd).rar" "E: \ data backup \ % Ymd %"
Echo OK!

Save the preceding command as backup. bat and double-click it to start data backup.
The first sentence is to create a variable % Ymd %. Get the date, % date: ~, through the system variable % date % :~, 4% indicates that the first four characters of the date are the year, % date :~ 5, 2% indicates that the two characters starting with 5th characters of the date are the month, and % date :~ 8, 2% indicates the number of dates. For example, the final result of the date is 20090620.
The second sentence is to use the value of the variable % Ymd % to create an empty folder.
The third statement is to use the MySQL command to back up mysql and store it in the E: \ data backup \ % ymd % folder. There are many similar commands, back up multiple databases.
The last step is to use WinRAR to compress the backup data, store the RAR file name created with the % Ymd % variable value, and delete the % Ymd % directory of the backup.
If you want the system to automatically back up regularly, you can execute this command periodically through the system task plan.

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.