Skip to content

Instantly share code, notes, and snippets.

@anytizer
Last active December 31, 2015 01:09
Show Gist options
  • Select an option

  • Save anytizer/7912203 to your computer and use it in GitHub Desktop.

Select an option

Save anytizer/7912203 to your computer and use it in GitHub Desktop.
Backup a MySQL databases in 4 different ways. 1. Full database backup (contains everything you need to restore the database) 2. Database structure only backup (includes VIEWs as well) 3. Data only backup - contains INSERT statements only 4. Routines only backup (stored procedures, user defined functions)
@echo off
SET HOSTNAME=localhost
SET USERNAME=root
SET PASSWORD=password
SET DATABASE=database
REM Backup everything
mysqldump --routines -h%HOSTNAME% -u%USERNAME% -p%PASSWORD% %DATABASE% > %DATABASE%-all.dmp
REM Backup table structures only, includes VIEWs as well
mysqldump --no-data -h%HOSTNAME% -u%USERNAME% -p%PASSWORD% %DATABASE% > %DATABASE%-structure.dmp
REM Backup data only
mysqldump --no-create-info --compact -h%HOSTNAME% -u%USERNAME% -p%PASSWORD% %DATABASE% > %DATABASE%-data-only.dmp
REM Backup routines only
mysqldump --routines --no-create-info --no-data -h%HOSTNAME% -u%USERNAME% -p%PASSWORD% %DATABASE% > %DATABASE%-routines.dmp
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment