Dump all mysql DBs
Snippet
Written with a loving hand by kitt some time around 08:38 on 7 June 2015
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