Mysql – thesql “drop database” takes time — why


mysql5.0 with a pair of databases "A" and "B", both with large innodb tables. "drop database A;" freezes database "B" for a couple minutes. Nothing is using "A" at that point, so why is this such an intensive operation?

Bonus points: Given that we use "A", upload data into "B", and then switch to using "B", how can we do this faster? Dropping databases isn't the sort of thing one typically has to do all the time, so this is a bit off the charts.

Best Solution

So I'm not sure Matt Rogish's answer is going to help 100%.

The problem is that MySQL* has a mutex (mutually exclusive lock) around opening and closing tables, so that basically means that if a table is in the process of being closed/deleted, no other tables can be opened.

This is described by a colleague of mine here:

One excellent impact reduction strategy is to use a filesystem like XFS.

The workaround is ugly. You essentially have to nibble away at all the data in the tables before dropping them (see comment #11 on the link above).