If you’ve ever wanted to perform a scheduled backup of your MySQL database hosted on a Windows OS, here’s some very basic steps:
First, create a .bat file anywhere on disk and add the following content to it:
“<MySQL_Install>\mysql\bin\mysqldump” –user root –password=password databaseName > C:\databaseNameBackup.sql
Replace MySQL_Install with a fully qualified folder structure.
Replace the root password with the correct password.
Replace the databaseName with the database you want to backup, the db name can be found in the following folder: \mysql\data\
Once the above has proven to work, you can create a “Scheduled Task” in Windows.
To find the “Add Scheduled Task”, simply go to Accessories – System Tools – Scheduled Tasks.
In the “Run:” browse to the location of your batch file created earlier.
Ensure you set the “run-as” correctly – typically a user with administrative rights on that Windows machine.
Finally, set a schedule for the backup – you do not need to stop MySQL or any application hitting it, it simply does a dump as a point-in-time export.
The example script I’ve provided will overwrite the .sql file every time the backup is executed. I guess you could include some logic to time-stamp the file if you want to keep more than one on disk.
Test your scheduled task by right-clicking on the newly created task and perform a run and ensure that the .sql file is being generated in the folder identified in the script.