Backup multiple MySQL databases into separate files – Windows

Years ago I wrote a post on how to Backup multiple MySQL databases into separate files (Linux). I get a lot of questions about how to do the same on Windows; here’s a script submitted by one of my readers:

:: MySQl DB user
set dbuser=xxxx

:: MySQl DB users password
set dbpass=xxxx

:: Switch to the MySQL data directory and collect the folder names
pushd "C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.5\data"

:: Loop through the folders and use the fnames for the sql filenames, collects all databases automatically this way

echo "hello"

echo "Pass each name to mysqldump.exe and output an individual .sql file for each"

FOR /D %%F IN (*) DO (
"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump.exe" --user=%dbuser% --password=%dbpass% --databases %%F > "C:\SQLBackup\%%F.%backupdate%.sql"
)
Tags: ,


Share This


 


5 Responses to Backup multiple MySQL databases into separate files – Windows

  1. […] Update: want to know how to do this on Windows? See my post Backup multiple MySQL databases into separate files – Windows. […]

  2. Very nice post. Information posted here is very helpful. I like the blog very much. Thanks to the admin of this blog.

  3. handy script, thanks.

    I think it’s missing a “set backupdate”.

    Although it’s locale dependant, you can use %date% and %time% to set it according to the current system date and time.

    For example, if %date% outputs “dd/mm/yyyy” and you want “yyyy-mm-dd” :

    set backupdate=%date:~-4%-%date:~3,2%-%date:~0,2%

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>