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
  • Save jorgehs91/c1b6dd9a16ad7ee5068b7e6b17ef5ab1 to your computer and use it in GitHub Desktop.
Save jorgehs91/c1b6dd9a16ad7ee5068b7e6b17ef5ab1 to your computer and use it in GitHub Desktop.

Revisions

  1. Jorge Henrique revised this gist May 24, 2021. 2 changed files with 11 additions and 6 deletions.
    11 changes: 11 additions & 0 deletions database.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    # 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
    6 changes: 0 additions & 6 deletions mysql-docker.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +0,0 @@
    # Backup
    docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql

    # Restore
    cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE

  2. Santiago Palladino created this gist Dec 22, 2015.
    6 changes: 6 additions & 0 deletions mysql-docker.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    # Backup
    docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql

    # Restore
    cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE