In this tutorial I’m going to show you how you can backup a mysql database using a batch file. Okay! I’ll tell you the truth, I basically made a similar tutorial maybe 5 months ago:
You may want to read on that first, especially the latter one. Because I don’t really want to repeat taking screenshots on how to use the task scheduler on Windows. Why you ask? Because It freezes on me.
Okay, I’ll make this quick. Here’s the code that you will need:
@echo off For /f "tokens=2-4 delims=/ " %%a in ('date /t')
do (set mydate=%%c-%%a-%%b) For /f "tokens=1-2 delims=/:" %%a in ('time /t')
do (set mytime=%%a%%b)
mysqldump -u root -p1234 modal_db -B>
You only need the last 2 lines to backup your database into the directory that you specified. But the first 3 lines, identifies the current date and time for you. So you’ll even know what time the backup was created based on the filename.
There are few things you need to modify though:
database user – root path - c:wampdb_backupsmodal_db password – 1234 database name – modal_db
If all those matches your current configuration. And wampserver is up and running. You can just launch the batch file (.bat) and the mysql dump file will be created. Just use the power of windows task scheduler to automate this task.
Your output filename will look like this: