Created
July 6, 2015 15:58
-
-
Save tzkmx/9cddc86a709f421cf2c7 to your computer and use it in GitHub Desktop.
MySQL dump schemas as CSV, a directory per schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
REM DANGER: Erase subdirectories without prompting user previously! | |
FOR /D /R %%D IN (*) DO ( | |
ECHO erasing %%D | |
RD /S /Q %%D | |
) | |
REM We use the output of SHOW DATABASES to build our list | |
FOR /F "usebackq tokens=1-2 delims=| " %%D in (`mysql -h %BackupHost% -u %BackupUser% -p%BackupPass% -e "show databases;"`) DO ( | |
REM Nested if's to exclude unwanted entries in list | |
IF NOT "%%D" == "Database" ( | |
IF NOT "%%D" == "information_schema" ( | |
IF NOT "%%D" == "performance_schema" ( | |
IF NOT "%%D" == "mysql" ( | |
REM Make a directory per schema | |
MKDIR %%D | |
REM Enter in it | |
PUSHD %%D | |
ECHO Dumping data in Schema: %%D | |
REM Backup{Host,User,Pass} are set as environment variables | |
mysqldump -h %BackupHost% -u %BackupUser% -p%BackupPass% -t -T . --fields-terminated-by=, --fields-escaped-by=\\ --lines-terminated-by=\r\n --fields-optionally-enclosed-by=0x22 %%D | |
REM Back to parent directory | |
POPD | |
))))) | |
REM Erase all *.sql found in every subdirectory from parent | |
FOR /R %%S IN (*.sql) DO ERASE %%~pxnS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment