September 7, 2016 - rob

Bash script to dump all databases from mariadb or mysql

Just a simple script to list all databases in mariadb or mysql and dump them.   Good if you ever wanted to start over.

 

#!/bin/bash
echo “Getting database list”
mysql -uroot -p -e “show databases” | grep -v Database | grep -v mysql| grep -v information_schema| grep -v test | grep -v “lost+found” | grep -v OLD > mysql.txt
filename=’mysql.txt’
echo “Start of database dumps”
while read p; do
echo “Dumping $p”
mysql -u root -p -e “drop database $p;”
done < $filename
rm mysql.txt

Linux