mysql - Drop multiple databases with names matching a pattern -


I want to leave all the databases that start with one word.

  abc xyz cms_db1 cms_db2 Cms_xyz pqr   

In the above example, I would like to exclude all the databases starting with the word "database". I think that the matriculation or shell script can do this. What is the best way?

Linux methods:

  #! / Bin / bash DB_STARTS_WITH = "cms" MUSER = "root" MPWD = "mypass" MYSQL = "mysql" dbs = "$ ($ MYSQL -u $ MUSER -p $ MPWD -Base 'show database')" for DB $ Dbs; If [["$ db" = ~ "^ $ {DB_STARTS_WITH}"]]; Then echo "$ db removal" $ MYSQL -u $ MUSER -p $ MPWD -On the "dropdown $ db"   

use of drop Participate at your own risk;)

Comments