cmd

Here’s a quick and simple guide to creating a short script to backup your MYSQL databases for your WAMP server.

To do this we will create a .bat file using notepad, or your favourite text editor, you can then even go onto automating the execution of this script using the in-built Windows Task Scheduler. I won’t bother going into detail, if you’ve already setup a WAMP server I assume you’re pretty capable with a computer already and the script is only a basic example for you to tailor and play with, but can be a lifesaver in nasty situations!

Open up notepad and write the script as shown below – changing any options to suit your own circumstances.

echo off
cd C:wampbinmysqlmysql5.1.53bin
cls
mysqldump -u user -p password database1_name > C:sql_dumpsdatabase1_name.sql
echo database1 sql dump created
mysqldump -u root database2_name > C:sql_dumpsdatabase2_name.sql
echo database2 sql dump created
echo ——————————–
echo All SQL Database Backups Completed
echo ——————————–
pause

Save the file as backup.bat. This script will now be executable and can be run to backup and take dumps of your databases.

A further look into what each line of the script is doing…

echo off
Turns off command-echoing
cd C:wampbinmysqlmysql5.1.53bin
Change directory to where your mysqldump.exe executable is installed
cls
Clears the screen. The user doesn’t need to see what we’ve been doing yet.
mysqldump -u user -p password database1_name > C:sql_dumpsdatabase1_name.sql
Creates a dump of the database called database1_name to the location C:sql_dumps as a file named database1_name.sql, using the MYSQL account details of username user and password password.
echo database1 sql dump created
Displays a message to say this step has been completed
mysqldump -u root database2_name > C:sql_dumpsdatabase2_name.sql
Creates a second dump for a second database called database2_name to the location C:sql_dumps as a file named database2_name.sql, using the MYSQL root account.
echo database2 sql dump created
Displays a message to say this step has been completed
echo ——————————–
echo All SQL Database Backups Completed
echo ——————————–
Displays a message to say all steps have been completed
pause
Suspends processing of the batch file displaying “Press any key to continue…”. I have simply added a pause to the end of the script to allow the user to see that the script has run and the messages which have been displayed.

Just a quick note you should notice I change directory to where the mysqldump.exe lives, the path for this maybe slightly different for yourself depending on where you placed your WAMP installation. To prevent you from having to take this step you could add the directory to the Windows Enviroment Variables… Path (Right-Click Computer – Advanced system properties), however this is only an optional extra step.