How to Create a MySQL Auto Backup on Your Windows Server

Rate this article: 1 Star2 Stars3 Stars4 Stars5 Stars (14 votes, average: 4.43)
Loading...

9 Easy steps to schedule MySQL auto backup on your Windows server

Losing all your data is the biggest nightmare any website administrator can face, even more so than facing a cyber-attack! It is not only a disaster from the security point of view, but it could ruin the very foundation of a business. That’s why, taking regular backups is one of the most important tasks on an administrator’s job task list. Many DBMSs (database management systems) offer easy tools that help admins take backups quite easily. However, some DBMSs, such as MySQL, don’t offer that convenience and that’s why you have to set up MySQL auto backups or MySQL scheduled backups.

Although there are many paid tools available to schedule MySQL auto backups, there’s an easy way you can do it without paying a single penny for it. Sounds good? Of course, it does. Here, we’ll be using simple windows batch script to create MySQL scheduled backup.

Ready to go? Let’s start!

Create MySQL Auto Backups in Windows Server Using Windows Batch Script

The process of creating scheduled MySQL backups is quite easy. All it involves is 9 steps!

  1. First, you need to open Notepad and save the following script:

Note: Please don’t forget to change the SET parameters and the mysqldump.exe location.

@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%") do (set mytime=%%a%%b)

SET backupdir=C:\xampp\htdocs\backup
SET mysqluername=root
SET mysqlpassword=somepassword
SET database=dbname

C:\xampp\mysql\bin\mysqldump.exe -uroot -pPASSWORD %database% > %backupdir%\%database%_%mydate%_%mytime%_.sql

2. Go to Start > All Programs > Accessories > Command Prompt to open Command Prompt.

3. Type Taskschd.msc.

4. Click on Create Task… option listed under Actions pane on the right-hand side.

5. Select the user with admin rights.

6. Click Run whether user is logged on or not and click Run with highest privileges.

7. Click on the Triggers tab on the top.

8. From the Actions tab, select the batch file that we created in the first step.

9. Click OK.

Congratulations! You have just scheduled MySQL auto backup on your Windows server. Quite easy, wasn’t it?

CodeGuard

Get CodeGuard at $1.63/Month Only! Save Up to 50% With ComodoSSLstore!

CodeGuard comes with amazing features like daily Automatic Backups, One-Click Restore, Malware Scanning, and Advanced 256-bit AES encryption.
Shop CodeGuard Backup Solution