MySQL DBA Tips Corner

     Return to the MySQL DBA Tips Corner.


Database Still Shows up After Successful DROP DATABASE Statement

by Jeff Hunter, Sr. Database Administrator


Contents

  1. Introduction
  2. Possible Solution


Introduction

For this article, I have the following three databases configured on my MySQL server:
mysql> show databases;
+--------------+
| Database     |
+--------------+
| jhunter_test |
| mysql        |
| test         |
+--------------+
3 rows in set (0.00 sec)
Assuming you have sufficient privileges, you now attempt to drop the database using the following statement:
mysql> drop database jhunter_test;
Query OK, 0 rows affected (0.00 sec)
All looks good until you attempt to view your databases:
mysql> show databases;
+--------------+
| Database     |
+--------------+
| jhunter_test |
| mysql        |
| test         |
+--------------+
3 rows in set (0.00 sec)
Hey, wait. I just dropped the jhunter_test database and yet it is still showing up on my system. How could that be? Read on for a possible answer and solution.
Possible Solution
A database is represented by a directory under the data directory, and the directory is intended for storage of table data. If you drop a database but yet its name still continues to show up when you issue the SHOW DATABASES; command, it is more than likely that the directory contained non-table files. The DROP DATABASE statement will remove all table files and then remove the directory that represented the database. It will not, however, remove non-table files, whereby making it not possible to remove the directory. This means that the database directory will continue to exist (albeit empty of any tables) and the SHOW DATABASES; command will continue to display it has a database.

If this occurs, you can really drop the database manually by removing any remaining files in the database directory and then the directory itself.

The newest releases of MySQL displays an error message when it cannot remove the directory, so this problem should not occur with users using a current release of MySQL.

mysql> drop database jhunter_test;
ERROR 1010 (HY000): Error dropping database (can't rmdir '.\jhunter_test\', errno: 17)


Copyright (c) 1998-2017 Jeffrey M. Hunter. All rights reserved.

All articles, scripts and material located at the Internet address of http://www.idevelopment.info is the copyright of Jeffrey M. Hunter and is protected under copyright laws of the United States. This document may not be hosted on any other site without my express, prior, written permission. Application to host any of the material elsewhere can be made by contacting me at jhunter@idevelopment.info.

I have made every effort and taken great care in making sure that the material included on my web site is technically accurate, but I disclaim any and all responsibility for any loss, damage or destruction of data or any other property which may arise from relying on it. I will in no case be liable for any monetary damages arising from such loss, damage or destruction.

Last modified on
Monday, 25-Jul-2005 20:17:27 EDT
Page Count: 23517