Backing up MySQL on Windows

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.

VN:F [1.9.22_1171]
Was this helpful? Please rate the content.
Rating: 10.0/10 (1 vote cast)
Backing up MySQL on Windows, 10.0 out of 10 based on 1 rating

About Darren Melanson

Darren is a development manager working on the ADEP product in Adobe Systems.
This entry was posted in Adobe LiveCycle ES, Adobe LiveCycle ES2 (9.0.x). Bookmark the permalink.

4 Responses to Backing up MySQL on Windows

  1. Darren Melanson says:

    Additionally, if you want to include the date in the file name, try this:
    C:\DatabaseNameBackup-%date:~-7,2%-%date:~-10,2%-%date:~-4,4%.sql
    This would generate a file called C:\DatabaseNameBackup-23-02-2011.sql

  2. Pete says:

    Thanks for posting this Darren. This helped me get off on the right foot setting up a backup scheme for an ASP website using MySQL. Note that the mysqldump syntax may vary slightly with MySQL version. The final script also encrypts the backup file with 7-Zip command line and e-mails it using CDOSYS yielding a simple, automated, offsite backup solution.

  3. Brian Finken says:

    Is there a way to secure the backup password so it is not stored as plain text? Also, without buying a 3rd party backup application.

  4. Alexander says:

    We would recommend our GUI backup tool for MySql – MySQL Backup FTP (MySqlBF) http://mysqlbackupftp.com/.

    Features:
    1. Run backups on a flexible schedule.
    2. MySqlBF can work as a service.
    3. Allow backup several databases from several websites.
    4. Tool have a completely Free and powerful version.
    5. MySqlBF allow to to save backups to the Network, on FTP and most popular cloud storage (Dropbox, Amazon S3, Google Drive, SkyDrive, Box).
    6. Connect to remote servers throws TCP, SSH or phpMyAdmin(unique feature)
    7. We offer a high quality support and detailed manuals.