MySQL: Backup Database using Batch File

By | August 29, 2015

Backup MySQL Database in Windows

The Backup User

CREATE USER 'backup'@'backup' IDENTIFIED BY 'backup'; 
GRANT FILE, LOCK TABLES, SELECT ON *.* TO 'backup'@'localhost' IDENTIFIED BY 'backup';

The Script

echo off
for /f "tokens=1-4 delims=/ " %%i in ("%date%") do (
	set dow=%%i
	set month=%%j
	set day=%%k
	set year=%%l
set datestr=%year%_%month%_%day%
cd C:wampbinmysqlmysql5.6.12bin
mysqldump --user=backup --password=backup myapp > D:BACKUPSmyapp_%datestr%.sql
echo Database Backups Completed

You may run this script using Scheduler to make your backup by weekly, monthly, etc.

Leave a Reply

Your email address will not be published. Required fields are marked *

14 − 9 =