Is there a way to reset all mysql databases except system databases?

I use mysqldump to automatically output all my databases to a text file and save this dump as a backup. I use the -all-databases option, which removes my databases, but also deletes system databases (information_schema, phpmyadmin, etc.), which I don't need.

Is there a way to dump all my databases using mysqldump without explicitly naming them on the command line (so I don’t need to change the backup script every time I create a new database), but ignore all system databases?

+3
source share
1 answer

bash script . .

#!/bin/sh
DATABASES="$(/lighttpd/local/bin/mysql --user=user --password=pass -Bse 'show databases')"

for db in ${DATABASES[@]}
do
if [ $db == "information_schema" ]
then
continue
fi
echo ${db}-$(date +%m-%d-%y).sql.bz2 is being saved in /backup/mysql
mysqldump --user=user --password=pass $db --single-transaction -R | bzip2 -c > ${db}-$(date +%m-%d-%y).sql.bz2
done
+3

Source: https://habr.com/ru/post/1744149/


All Articles