Dump all mysql DBs

Snippet

Two ways. First way:

$ mysqldump -u root -p --all-databases > alldb.sql

Import this way:

$ mysql -u root -p < alldb.sql

Or, second way, this bash script, with edits:

#!/bin/bash
 
USER="root"
PASSWORD="THISISMYROOTPASSWORD"
#OUTPUT="/Users/kitt/mysql-dumps"
 
#rm "$OUTPUT/*gz" > /dev/null 2>&1
 
databases=`mysql -u $USER -p$PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
 
for db in $databases; do
    if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] ; then
        echo "Dumping database: $db"
        mysqldump -u $USER -p$PASSWORD --databases $db > `date +%Y%m%d`.$db.sql
       # gzip $OUTPUT/`date +%Y%m%d`.$db.sql
    fi
done