Drop multiple tables in mySQL / MariaDB

To start with. You can’t. Not directly, anyway. There is no “drop table prefix_%;”, so stop looking.

This seems to be the easiest workaround that we’ve found based on information shared here.

So here’s how we did it. For reference, anywhere a word or a phrase is wrapped in greater than / less than signs, that’s where you use your own <information>.

First you need to get into mySQL via ssh.

mysql -u <database-name> -p

Then key in your password to get to the mysql command prompt. Once there you need to find the actual database you want to work with:

show databases;
| Database |
| information_schema |
| yaaygnacua |
2 rows in set (0.001 sec)

99% of the time it will be “information_schema” and the database you want (in the above example it’s “yaaygnacua”). Then use the database:

use <database>;

and make sure you’re looking at the right tables by using:

show tables;

Once you’ve decided what your wildcard can be key this line in with your wildcard:


Assuming your wildcard hits something, this will generate a string that will look similar to this:

DROP TABLE mucvkd_wp_ebay_store_categories,mucvkd_wp_woocommerce_tax_rate_locations,mucvkd_wp_ebay_jobs,mucvkd_wp_mailchimp_jobs,mucvkd_wp_wfconfig,mucvkd_wp_wftrafficrates,mucvkd_wp_wflivetraffichuman

DROP TABLE mucvkd_wp_ebay_store_categories,mucvkd_wp_woocommerce_tax_rate_locations,mucvkd_wp_ebay_jobs,mucvkd_wp_mailchimp_jobs,mucvkd_wp_wfconfig,mucvkd_wp_wftrafficrates,mucvkd_wp_wflivetraffichuman;

Copy and paste that code right back into mysql, and most importantly, add a semi-colon at the end.

And voilà, your tables are gone.

Generally a tool my phpMyAdmin would be a much faster solution to dropping multiple tables, but when you’ve got a database with thousands of spurious tables, those types of applications will usually choke when trying to display, select, and delete that many tables.

Quick Caution

If your wildcard is too loose (as in result below only using “i”), you’ll get spurious results. It seems that the spurious result are all upper case, but do your own due diligence. Just grab the actual table names and paste them after a “drop tables” command. (and don’t forget the trailing semi-colon).


Quick Caution 2

If your wildcard is too loose, you may get more results that mysql will return. Keep your eyes open for partial table names. Just grab the actual table names and paste them after a “drop tables” command. (and don’t forget the trailing semi-colon). If you accidentally try to drop a partial table, you won’t hurt anything, you’ll just get an error “ERROR 1051 (42S02): Unknown table”

Leave a Comment

Powered by Paranoid Hosting™. 'Cause you never know...