Backup multiple MySQL databases into separate files – Windows
| 06-Mar-2012 | Posted by Sonia Hamilton under MySQL, 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" )
Share This
[...] Update: want to know how to do this on Windows? See my post Backup multiple MySQL databases into separate files – Windows. [...]
Very nice post. Information posted here is very helpful. I like the blog very much. Thanks to the admin of this blog.
I’m glad you like it! Sonia.
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%Great, thanks!