How to delete multiple Databases in Linux

This method requires root privileges.

Heads up, use this method at your own risk. I would not recommend using this approach in production level environment.

Steps:

  1. Create a shell script drop_multiple_db.sh then paste the following contents in it.
                [root@testserver ~]$vi drop_multiple_db.sh
                
                #!/bin/bash
    
                USER="username"
                PWD="password"
    
                DBS="
                database_name1
                database_name2
                database_name3
                database_nameN
                "
               for db in $DBS; do
    
               echo "Deleting $db"
               mysql -u$USER -p$PWD -Bse "drop database $db"
    
               done    
               
  2. Set User and Password.
  3. Modify the contents of the DBS variable, write all the database names that you want to drop.
  4. Save and Quit.
  5. Run the Shell.
            [root@testserver ~]$sh drop_multiple_db.sh
            

Leave a Reply

Your email address will not be published. Required fields are marked *