Skip to content

Instantly share code, notes, and snippets.

@jorgehs91
Forked from spalladino/mysql-docker.sh
Last active May 24, 2021 21:36
Show Gist options
  • Select an option

  • Save jorgehs91/c1b6dd9a16ad7ee5068b7e6b17ef5ab1 to your computer and use it in GitHub Desktop.

Select an option

Save jorgehs91/c1b6dd9a16ad7ee5068b7e6b17ef5ab1 to your computer and use it in GitHub Desktop.
Backup and restore database routines
# Get regular database gziped
mysqldump -h <database host> --user=<database username> --password=<password> --single-transaction <database name> | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | gzip > /tmp/database_no-definer.sql.gz
# Restore regular database gziped
zcat /tmp/database.sql.gz | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | mysql -h <database_host> -u <username> -p <password> <database_name>
# Get database from docker container
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore database to docker container
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment