Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

There are quite a few discussion on the Interweb on how to backup based on the wildcard table name, but how about wildcard database name?

e.g.

If I have databases named

foo1
foo2
foo3
 .
 .
fooN
bar1

I want to only backup db with name prefixed foo, is it possible?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You select database names from tables table in information_schema database. you can use filter to filter by your prefix. the use outputed database names to export using mysqldump. a practical example is as follows:

mysqldump -u root -pPASSWORD --databases $(
  mysql -uroot -p -N information_schema \
    -e "SELECT DISTINCT(TABLE_SCHEMA)
        FROM tables
        WHERE TABLE_SCHEMA LIKE 'prefix%'"
) > /tmp/backup.sql
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.