Skip to content

Instantly share code, notes, and snippets.

@procky
Last active August 29, 2015 14:14
Show Gist options
  • Save procky/d20747ffb22de4bc79df to your computer and use it in GitHub Desktop.
Save procky/d20747ffb22de4bc79df to your computer and use it in GitHub Desktop.
Dump Mysql tables from a database, 1 table per file, using a bat file. db tables to separate sql files via Windows Batch script.
@echo off
set /p userDBName= Enter db name to backup:
set /p userHost= Enter mysql host (e.g. 127.0.0.1):
set /p userName= Enter mysql username (e.g. root):
:: This is set to my local time, in uk time format I would presume
md C:\backups\%userDBName%-%DATE:~-4%-%DATE:~-7,2%-%DATE:~0,2%
:: You'd probably need to edit this to get to your mysql.exe
cd C:\xampp\mysql\bin
echo Enter your mysql password
mysql -s -e "SHOW TABLES FROM "%userDBName% -h %userHost% -u %userName% -p --skip-column-names > C:\backups\tables.txt
echo Enter your mysql password again
for /f %%A in (C:\backups\tables.txt) DO (mysqldump -h %userHost% -u %userName% -p %userDBName% %%A > c:\backups\%userDBName%-%DATE:~-4%-%DATE:~-7,2%-%DATE:~0,2%\%%A.sql)
echo Export finished
pause >nul
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment