geohernandez
Menu
  • HOME
  • ABOUT
  • CONTACT ME
  • WORK WITH GEO
    • Data Specialist
    • Speaker Events
    • Resume
  • English
    • English
    • EspaƱol
Menu

Solving drop database error: can’t rmdir in MySQL

Posted on February 11, 2021February 14, 2021 by geohernandez

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:

[crayon-681dcbe6564c8586569636/]

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:

[crayon-681dcbe6564d7736717436/]

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.

Category: Chronicles from the trenches, MySQL

Leave a Reply Cancel reply

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

Search for articles

Recent Posts

  • Quick Guide: BigQuery Service Account Setup Using gcloud
  • The Art of Data Modeling in AI times
  • Getting Started with Snowflake’s Snowpipe for Data Ingestion on Azure

Categories

  • Airflow (1)
  • Azure (6)
  • Azure DevOps (2)
  • Bash script (1)
  • Blog (1)
  • Cassandra (3)
  • Chronicles from the trenches (26)
  • Data Architecture (3)
  • Data Engineering (11)
  • DB optimization (2)
  • Events (2)
  • GIT (1)
  • MySQL (1)
  • Python (7)
  • Snowflake (3)
  • SQL Saturday (1)
  • SSIS (2)
  • T-SQL (5)
  • Uncategorized (2)

Archives

  • May 2025 (1)
  • March 2025 (1)
  • January 2025 (2)
  • October 2024 (1)
  • July 2024 (1)
  • May 2024 (1)
  • December 2023 (1)
  • November 2023 (1)
  • August 2023 (1)
  • June 2023 (1)
  • December 2022 (1)
  • November 2022 (1)
  • July 2022 (1)
  • March 2022 (1)
  • September 2021 (1)
  • May 2021 (1)
  • March 2021 (1)
  • February 2021 (3)
  • December 2020 (1)
  • October 2020 (3)
  • September 2020 (1)
  • August 2020 (1)
  • January 2020 (1)
  • August 2019 (1)
  • July 2019 (1)
  • June 2019 (1)
  • May 2019 (1)
  • April 2019 (1)
  • March 2019 (1)
  • November 2018 (3)
  • October 2018 (1)
  • September 2018 (1)
  • August 2018 (2)
© 2025 geohernandez | Powered by Minimalist Blog WordPress Theme