Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 111461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:23:20+00:00 2026-05-11T02:23:20+00:00

Im runing mySQL in a server where i need to drop tons of databases

  • 0

Im runing mySQL in a server where i need to drop tons of databases (after some testing with the server). All databases that i need to drop have the same prefix ‘Whatever_’.

After the prefix, the names are random. So you have your Whatever_something, Whatever_232, Whatever_blabla, …. , Whatever_imthelast.

I will be doing this job quite some times so i was wondering what would be the best way to do this?

EDIT: I can use any kind of language or plug in for mysql… so we CAN do this in some ways. Right now, i asked the guy that is generating the databases to give me a .txt with each name in a line… so im coding a quick php that will take a file and delete all the databases in it, later i will try the % answer(if it works, it takes the correct answer for sure its the easier way). Anyway i would like to do this the easier way coz i wont be able to support this code(other guys will and you know… )

edit 2: The use of a wildcard didnt work: #1008 – Can’t drop database ‘whatever_%’; database doesn’t exist

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T02:23:21+00:00Added an answer on May 11, 2026 at 2:23 am

    The basic idea is to run ‘show tables’ in your database, and use the results from that to select the tables you want. I don’t think MySQL lets you do anything with the resultset from ‘show tables’, but I’m probably wrong.

    Here’s a quick-and-dirty solution using the shell:

    mysql -u your_user -D your_database_name -e 'show tables' -s |    egrep '^Whatever_' |    xargs -I '@@' echo mysql -u your_user -D your_database_name -e 'DROP TABLE @@' 

    That will print out all the shell commands to drop the tables beginning with ‘Whatever_’. If you want it to actually execute those commands, remove the word ‘echo’.

    EDIT: I forgot to explain the above! I don’t know how familiar you are with shell scripting, but here goes:

    mysql -u your_user -D your_database_name -e 'show tables' -s 

    prints out a list of all your tables, with the header ‘Tables_in_your_database_name’. The output from that is piped (the | symbol means ‘piped’, as in passed-on) through the next command:

    egrep '^Whatever_' 

    searches for any lines that begin (that ^ symbols means ‘beings with’) the word ‘Whatever_’ and only prints those. Finally, we pipe that list of ‘Whatever_*’ tables through the command:

    xargs -I '@@' echo mysql -u your_user -D your_database_name -e 'DROP TABLE @@' 

    which takes each line in the list of table names, and inserts it instead of the ‘@@’ in the command

    echo mysql -u your_user -D your_database_name -e 'DROP TABLE @@' 

    So if you had a bunch of tables named ‘Whatever_1’, ‘Whatever_2’, ‘Whatever_3’, the generated commands would be:

    echo mysql -u your_user -D your_database_name -e 'DROP TABLE Whatever_1' echo mysql -u your_user -D your_database_name -e 'DROP TABLE Whatever_2' echo mysql -u your_user -D your_database_name -e 'DROP TABLE Whatever_3' 

    Which would output the following:

    mysql -u your_user -D your_database_name -e 'DROP TABLE Whatever_1' mysql -u your_user -D your_database_name -e 'DROP TABLE Whatever_2' mysql -u your_user -D your_database_name -e 'DROP TABLE Whatever_3' 

    I hope that was enough detail, and that I’m not just beating anyone over the head with too much information. Good luck, and be careful when using the ‘DROP TABLE’ command!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a myisam only dedicated 32 GB RAM mysql server that is running
I have a production database server running on MYSQL 5.1, now we need to
I have a problem with a MySql server causing it to freeze all the
I'm testing MySQL as a replacement for SQL server and I'm running into something
Can I connect to a Ubuntu server, that is running MySQL using ADO.NET or
So I want to create a JDBC connection to MySQL server that is installed
I have a small mysql database (200 MB) running on a server. The application
I need to write some scripts to carry out some tasks on my server
I'm running a SQL server and need to run some commands using the SELECT
In my production environment, I have a single instance of MySQL server running on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.