Skip to content

Instantly share code, notes, and snippets.

@benfavre
Created August 18, 2021 10:23
Show Gist options
  • Save benfavre/a4d39e7acca90a75d68474fbf611e43d to your computer and use it in GitHub Desktop.
Save benfavre/a4d39e7acca90a75d68474fbf611e43d to your computer and use it in GitHub Desktop.

Revisions

  1. benfavre created this gist Aug 18, 2021.
    8 changes: 8 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    # DUMP
    mysql -N -e 'show databases' | while read dbname; do mysqldump --complete-insert --routines --triggers --single-transaction "$dbname" > "$dbname".sql; done

    # IMPORT
    for sql in *.sql; do dbname=${sql/\.sql/}; echo -n "Now importing $dbname ... "; mysql $dbname < $sql; echo " done."; done


    ## Credits https://ma.ttias.be/mysql-back-up-take-a-mysqldump-with-each-database-in-its-own-sql-file/