Solving drop database error: can’t rmdir in MySQL

Sometimes, the only thing that we want is to drop a database(not in PRODUCTION) and recreate it from scratch, especially when we are in the process of automating the deployment of our MySQL databases, for instance using liquibase. Therefore, it is not uncommon in an initial testing process to wish to drop and recreate our tested database.

Recently, I found the following error message after to try execute a simple and rarely applied DROP DATABASE statement:

ERROR 1010 (HY000): Error dropping database (can't rmdir './db_test', errno: 39)

The reasons behind this error could be many, in my case, it was a problem related to an existing connection that was using the target database, in which case the showprocess list is your best friend, once that you have killed the process which was pointing out to the DB, the next step consists in check the data directory, the easy way is inside MySQL execute the following command:

SHOW VARIABLES WHERE Variable_name LIKE '%datadir%';

Once that you check into the datadir, you need to verify that exists a folder with the same name than the database that you want to drop, localice and inside of this folder check that not exists any file with the extensions:

  • .BAK
  • .DAT
  • .HSH
  • .MRG
  • .MYD
  • .MYI
  • .cfg
  • .db
  • .ibd
  • .ndb

As the official MySQL documentation says: “If other files or directories remain in the database directory after MySQL removes those just listed, the database directory cannot be removed”. So, you only need to be sure of having enough permission for removing any file which has the extensions mentioned above and remove it manually, to do this you only need to and issue the DROP DATABASE statement again.

I hope this simple trick would be useful, especially in lower environment and during testing automation process.

geohernandez

Share
Published by
geohernandez

Recent Posts

Integrating Azure Blob Storage with Snowflake on AWS: A Guide to Storage Integration and Staging Data

This article offers a comprehensive, step-by-step guide for integrating Azure Blob Storage with a Snowflake…

4 hours ago

Getting Started with SnowSQL: Connecting to Your Snowflake Account

In this quick guide, we’ll walk through the essential steps to connect to Snowflake using…

3 weeks ago

A new step in my career as a Senior Data Architect

I am thrilled to share that I have embarked on a new professional journey as…

4 months ago

Data Modeling and its relevance in the Cloud Era

Since 2005, I've immersed myself in the dynamic world of data and its modeling. It's…

6 months ago

Formatting our Postgres scripts with pgformatter in DBeaver

Are you a PostgreSQL enthusiast using DBeaver on a Windows Platform? If you find yourself…

11 months ago

Looking back to Kimball’s approach to Data Warehousing

Over time, it's fascinating to witness how certain concepts, approaches, or visions age. Time, in…

12 months ago