Backup MySQL database dos script under Windows

Source: Internet
Author: User

echo Off & setlocal enableextensions
::----------Configuration Items----------
:: Backup placement path, plus
Set Backup_path=d:\backup
:: Database name to back up, multiple spaces separated
Set databases=1688 ABC Ceshi
:: MySQL User Name
Set Username=root
:: MySQL Password
Set Password=root
:: MySQL Bin directory, plus
:: If you can use dump directly (add the MySQL Bin directory to the environment variable at installation), leave this blank
Set mysql=d:\progra~1\phpstudy\mysql\bin\
:: WinRAR with command-line tools executable path, long file name note in Dos long file name writing method
Set Winrar=d:\progra~1\winrar\rar.exe
::----------Do not modify the following----------
Set year=%date:~0,4%
Set month=%date:~5,2%
Set day=%date:~8,2%
:: If the input time in DOS to return is not 24-hour system (no 0 fill), please modify this here
Set hour=%time:~0,2%
Set minute=%time:~3,2%
Set second=%time:~6,2%
Set dir=%backup_path%\%year%-%month%-%day%_%hour%%minute%%second%

Set addon=%year%%month%%day%%hour%%minute%%second%
:: Create dir
If not exist%dir% (
mkdir%dir% 2>nul
)

If not exist%dir% (
echo Backup path:%dir% NOT exists, create DIR failed.
Goto exit
)
CD/D%dir%

:: Backup
echo Start Dump databases ...
For%%D in (%databases%) do (
echo Dumping Database%%D ...
%mysql%mysqldump-u%username%-p%password%%%D >%%d.%addon%.sql
:: WinRAR
If exist%winrar% (
%winrar% a-k-r-s-m1-ep1%%d.%addon%.rar%%d.%addon%.sql
del/f/s/q%%d.%addon%.sql 2>null
)
)
Echo Done
: Exit

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.