Answer the question
In order to leave comments, you need to log in
How to get database names excluding system ones?
Wrote a MySQL dump script to files for myself. I know it's a bike, but for me to train. And here is the result on the screen:
Here is the script itself:
#!/bin/bash
#
DUMP_FOLDER=${PWD}/dump
DB_USER=root
DB_PASSWORD=root
DB_HOST=localhost
[ -d ${DUMP_FOLDER} ] || mkdir ${DUMP_FOLDER}
DB_LIST=$(echo "SHOW DATABASES;" | mysql --host=${DB_HOST} --user=${DB_USER} --password=${DB_PASSWORD})
for DB_NAME in $DB_LIST
do
DB_FOLDER=${DUMP_FOLDER}/${DB_NAME}
[ -d ${DB_FOLDER} ] || mkdir ${DB_FOLDER}
TABLE_LIST=$(echo "USE ${DB_NAME};SHOW TABLES;" | mysql --host=${DB_HOST} --user=${DB_USER} --password=${DB_PASSWORD})
for TABLE_NAME in $TABLE_LIST
do
mysqldump --host=${DB_HOST} --user=${DB_USER} --password=${DB_PASSWORD} -B ${DB_NAME} --tables ${TABLE_NAME} > ${DB_FOLDER}/${TABLE_NAME}.sql
done
done
Answer the question
In order to leave comments, you need to log in
DB_LIST=$(echo "SHOW DATABASES where \`database\` != 'mysql' AND \`database\` not like '%_schema';" | mysql --host=${DB_HOST} --user=${DB_USER} --password=${DB_PASSWORD})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question