Skip to content

Instantly share code, notes, and snippets.

@TheRatG
Last active June 4, 2018 17:42
Show Gist options
  • Save TheRatG/f3c6be7031b8ceec027da1fd85c40f1c to your computer and use it in GitHub Desktop.
Save TheRatG/f3c6be7031b8ceec027da1fd85c40f1c to your computer and use it in GitHub Desktop.
mysqldump excluded tables
#!/usr/bin/env bash
PASSWORD=password
USER=user
DATABASE=database
DB_FILE=/tmp/${DATABASE}.sql.gz
EXCLUDED_TABLES=(
table_1
table_2
table_3
)
IGNORED_TABLES_STRING=''
for TABLE in "${EXCLUDED_TABLES[@]}"
do :
IGNORED_TABLES_STRING+=" --ignore-table=${DATABASE}.${TABLE}"
done
mysqldump --no-data --skip-lock-tables --skip-add-locks --routines --user=${USER} --password=${PASSWORD} ${DATABASE} | gzip > ${DB_FILE};
mysqldump --no-create-info --skip-lock-tables --skip-add-locks --extended-insert -u${USER} -p${PASSWORD} ${DATABASE} ${IGNORED_TABLES_STRING} | gzip >> ${DB_FILE};
echo "${DB_FILE}";
# import
# zcat ${DB_FILE} | mysql --user=${USER} --password=${PASSWORD} -D${DATABASE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment