Automatic MySQL Backup using Batch File on Windows

Backup of your database is important. You can do the backup manually, but automatic backups with regular time intervals are good and time-saving. In this post, I am specifically talking about MySQL. Unfortunately, there is no free solution for auto backup. However, there is a simple workaround available on the Windows platform to make MySQL backup automatically and freely. For this, you require a batch file and you have to write a batch script. Here are the steps for MySQL Database Auto Backup:

MySQL Auto Backup Steps:


1. Create a backup.bat file

2. Open the file in Notepad and add this:

@echo off
start "" "C:\wamp\bin\mysql\mysql5.6.12\bin\mysqldump.exe(your mysql dump address)" --user root --password=(provide your db password here) databaseNameHere --result-file="D:\database backup location\SqlFileName.sql" --database databaseNameHere


Now let's break down the string we have mentioned in the above file:

C:\wamp\bin\mysql\mysql5.6.12\bin\mysqldump.exe(your mysqldump address)
This is the location of mysqldump file. Please locate your dump file path and paste its location with name and extension here.

user root
Here you should provide your MySQL username. In my case, it is root.

password=(provide here)
Your MySQL password.

databaseNameHere
The database for which backup is required!

result-file="D:\where you want path with SqlFileName.sql"
This will be the location where you want to save the backup file. Please choose the backup name wisely. If you want to place multiple backup files, you can use the date in your file name like this:
.%date:~10,4%-%date:~7,2%-%date:~4,2% Blockquote

3. The third and final step: Use this batch file in your Windows Task Scheduler. Here is the detailed guide on how to add it to Windows Task Scheduler.

So, within three steps, you can regularly make backups!

Post a Comment

0 Comments