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.