1 @echo off2 rem MySQL backup script supports full backup3REM Incremental backup requires MySQL service plus--log-Bin parameter Execution4REM Data restore Mysql-u Root-p <Backup.sql5REM =====================6 REM Global Variables7Set dump=Mysqldump.exe8Set rand=%random%9REM =====================Ten One REM detects if the MySQL path is added to the path variable A Echo=========================================== - Echo "Data Restore command: Mysql-u root-p < Backup.sql" - Echo=========================================== the Echo. - Echodetect if MySQL is added to environment variables ... - Echo%PATH% | findstr MySQL >nul - + if%errorlevel% EQU0Goto Dobackup - if%errorlevel% EQU1Goto Notinpath + A :d obackup at Echo. - Echo= = Backup Option = = -set/puname=Enter user name: - Echo. - Echodo you want to back up all databases? - Choice in if%errorlevel% EQU1Goto BACKUPALLDB - if%errorlevel% EQU2Goto BACKUPSPECIALDB to Pause + Exit - the : Backupalldb * Echo. $ Echoback up all databasesPanax Notoginseng%dump%-u root-p--all-databases > backup_%date%_%rand%. SQL - Echo. the if%errorlevel% EQU2(Del backup_%date%_%rand%.sql &&goto Pwderror) + EchoBackup complete, backup file is backup_%date%_%rand%. SQL A Pause the Exit + - : Backupspecialdb $ Echo. $ Echobacking up a specified database -set/p db=Enter the database name: -%dump%-u root-p%db% >"%db%_%date%_%rand%". SQL the Echo. - if%errorlevel% EQU2(Del%db%_%date%_%rand%.sql &&goto Pwderror)Wuyi EchoBackup complete, backup file is%db%_%date%_%rand%. SQL the Pause - Exit Wu - :p Wderror About Echo. $ Echo***Wrong password! - Echo. - Echoexit the program with any key -Pause>nul A Exit + the : Notinpath - Echo**MySQL path is not in environment variable $ Echo. the Echodetect current working path ... the dir| findstr%dump% >nul the if%errorlevel% EQU0Goto Dobackup the if%errorlevel% EQU1Goto Notinbindir - Pause in Exit the the : Notinbindir About Echo* * The current path does not contain%dump% the Echo. the EchoPlease add the MySQL path to the environment variable, or copy the script to the mysql/under the Bin folder the Echo. + Echoexit the program with any key -Pause>nul theExit
()
MySQL backup script under Windows