Error Dropping Database (Can't rmdir '.test\', errno: 17)

MysqlSqlPhpmyadmin

Mysql Problem Overview


Basically, I was taught on how to create a root password using the "mysqladmin -u root -p password" command, this was done all through the windows command editor. Now, the next process was to display the default databases (info. schema, mysql and test) which was achieved by using "SHOW DATABASES;"

But according to the book, we had to delete the redundant test file and the following error pops up:

>Error Dropping Database (Can't rmdir '.test', errno: 17)

The command put to use was DROP DATABASE test;

I am using MYSQL and PHPMYADMIN. Any help on how to drop the file with no errors?

Mysql Solutions


Solution 1 - Mysql

A database is represented by a directory under the data directory (usually /var/lib/mysql), and the directory is intended for storage of table data.

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.

MySQL displays an error message when it cannot remove the directory

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

Solution 2 - Mysql

I ran into this same issue on a new install of mysql 5.5 on a mac. I tried to drop the test schema and got an errno 17 message. errno 17 is the error returned by some posix os functions indicating that a file exists where it should not. In the data directory, I found a strange file ".empty":

sh-3.2# ls -la data/test
total 0
drwxr-xr-x   3 _mysql  wheel  102 Apr 15 12:36 .
drwxr-xr-x  11 _mysql  wheel  374 Apr 15 12:28 ..
-rw-r--r--   1 _mysql  wheel    0 Mar 31 10:19 .empty

Once I rm'd the .empty file, the drop database command succeeded.

I don't know where the .empty file came from; as noted, this was a new mysql install. Perhaps something went wrong in the install process.

Solution 3 - Mysql

Go to the datadir* for your mysql installation and rm the databases manually. It can be

/usr/local/var/mysql

Then,

rm -R <Your DB name>

Notes:

* To check datadir for your installation,

vim the mysql.server file and find it there.

Solution 4 - Mysql

For phpmyadmin, go to xampp\mysql\data and simply delete the database folder. Worked for me !!

Solution 5 - Mysql

If it is XAMPP, Do the following:

cd /opt/lampp/var/mysql;
sudo su;
rm -rf test;

Hope this helps.

Solution 6 - Mysql

I just ran into this problem with WAMP and the phpMyAdmin that comes with it. To remove the database and make the error go away. I went into C:\wamp\bin\mysql\mysql5.5.24\data\ and deleted the folder for the database in question.

Then I refreshed the page at phpMyAdmin, and the database was gone.

Solution 7 - Mysql

Just to add to the responses so far: In Windows 10, the data files are kept here...

C:\ProgramData\MySQL\MySQL Server [m.n]\data

There will be directories for each schema in your database. You will want to go inside the schema you are trying to drop, manually delete any superfluous files then try the drop command again.

Any workbench changes against a database will get stored in this location. For example, I had this error following a reverse engineering exercise on one of my databases and saving the changes which get stored in a .mwb file in this location.

Solution 8 - Mysql

You can delete the data in the sql directory.

For me i was using AMPPS on windows 10. I went to the AMPPs installtion directory. for me it was :

D:\Program Files (x86)\Ampps\mysql\data

because i have it installed on my secondary drive.

Then refresh your SQL client and you will see it's gone.

Solution 9 - Mysql

You may need to check two things.

1- Database Foleder's permission The database you wants to delete must have the same owner as mysql process has.

2- Directory Must be empty Goto the mysql data directory and verify that directory is empty

After that connect your mysql cli and run drop database command again.

Solution 10 - Mysql

Go through this and remove corresponding cache files in selected db then after you can drop your database

First find Your MySQL Data Directory Containing Your selected DB

Linux

  • Open up MySQL's configuration file: less /etc/my.cnf

  • Search for the term "datadir": /datadir

  • If it exists, it will highlight a line that reads: datadir = [path]

  • You can also manually look for that line. It typically would be found under a section heading of [mysqld] but it does not necessarily have to be found there.

  • If that line does not exist, then MySQL will default to: /var/lib/mysql.

Windows

  1. Open up MySQL's configuration file into Notepad: my.ini

The my.ini will be located in the MySQL program folder, which would be wherever it got installed. If you did not install MySQL, then use the Windows "search" feature to look for my.ini. You could also manually search for it by browsing to [drive]:\Program Files\MySQL\MySQL Server 5.5.

  1. Do a search in Notepad to find the term "datadir".

  2. If it exists, it will highlight a line that reads: datadir = [path]

  3. You can also manually look for that line. It typically would be found under a section heading of [mysqld] but it does not necessarily have to be found there.

  4. If that line does not exist, then you'll probably find it under [drive]:\ProgramData\MySQL\MySQL Server 5.5\data.

NOTE: The "ProgramData" folder may be hidden. You may have to type the explicit path into Windows Explore

Solution 11 - Mysql

mysql -s -N -username -p information_schema -e 'SELECT Variable_Value FROM GLOBAL_VARIABLES WHERE Variable_Name = "datadir"'

The command will select the value only from MySQL's internal information_schema database and disables the tabular output and column headers.

Output on Linux [mine result]:

/var/lib/mysql

or

mysql> select @@datadir;

on MYSQL CLI

and then

cd /var/lib/mysql && rm -rf test/NOTEMPTY

change path based on your result

Solution 12 - Mysql

In my case I didn't see any tables under my database on phpMyAdmin I am using Wamp server but when I checked the directory under C:\wamp\bin\mysql\mysql5.6.12\data I found this employed.ibd when I deleted this file manually I was able to drop the database from phpMyAdmin smoothly without any problems.

Solution 13 - Mysql

I my case the problem was a residual dump file in the database directory. That file was probably generated during a backup script test I had been working on. Once I manually deleted the file I could then drop the database.

Solution 14 - Mysql

I had the same issue (mysql 5.6 on mac) with 'can't rmdir..'-errors when dropping databases. Leaving an empty database directory not possible to get rid of. Thanks @Framework and @Beel for the solutions.

I first deleted the db directory from the Terminal in (/Applications/XAMPP/xamppfiles/var/mysql).

For further db drops, I also deleted the empty test file. In my case the file was called NOTEMPTY but still containing 0:

sudo ls -al test
total 0
drwxrwx---   3 _mysql  _mysql  102 Mar 26 16:50 .
drwxrwxr-x  18 _mysql  _mysql  612 Apr  7 13:34 ..
-rw-rw----   1 _mysql  _mysql    0 Jun 26  2013 NOTEMPTY

Chmod first and then

sudo rm -rf test/NOTEMPTY

No problems dropping databases after that

Solution 15 - Mysql

just go to data directory in my case path is "wamp\bin\mysql\mysql5.6.17\data" here you will see all databases folder just delete this your database folder the db will automatically drooped :)

Solution 16 - Mysql

I ran into this problem, and when I checked out the database directory, there were a number of exp files (the ibd and frm files had been removed). Listing the files to look at their attributes (since the owner already had rw privileges on the files)

lsattr *.exp
-------------e-- foo.exp
-------------e-- bar.exp

Man page says

       The  'e'  attribute  indicates that the file is using extents for mapping the blocks on disk.
       It may not be removed using chattr(1).

You actually can chattr -e these files, but mysql still won't let you drop the database. Removing the files with rm, however, allows the database to be dropped cleanly.

Solution 17 - Mysql

It happens because you may have copied /var/lib/mysql folder's database folder from another server to your server. But you haven't copied these files: /var/lib/mysql/ib_buffer_pool /var/lib/mysql/ibdata1 /var/lib/mysql/ib_logfile0 /var/lib/mysql/ib_logfile1 /var/lib/mysql/ibtmp1 So you can create a new db and tables you are able to drop them but you can't drop the databases that you have copied from another server and you are also not able to explore the same database that you copied from another server. So I also copied that files : ib_buffer_pool,ibdata1,ib_logfile0,ib_logfile1,ibtmp1 after that everything worked.

Solution 18 - Mysql

Anybody coming from Manjaro/Arch, installing XAMPP with PHP8 and then downgrading to 7.4 will get this error. To fix, simply go to /opt/lampp/var/mysql/ with Thunar as root user, and delete the database file with the same database name in question and database should be gone. You can get the database name with PhpMyAdmin.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSidView Question on Stackoverflow
Solution 1 - MysqlShakti SinghView Answer on Stackoverflow
Solution 2 - MysqlBeelView Answer on Stackoverflow
Solution 3 - MysqlNerveView Answer on Stackoverflow
Solution 4 - MysqlFloccinaucinihilipilification.View Answer on Stackoverflow
Solution 5 - MysqlNasif Md. TanjimView Answer on Stackoverflow
Solution 6 - MysqlJ86View Answer on Stackoverflow
Solution 7 - MysqlIqbalHamidView Answer on Stackoverflow
Solution 8 - MysqlmoeiscoolView Answer on Stackoverflow
Solution 9 - MysqlMansur Ul HasanView Answer on Stackoverflow
Solution 10 - MysqlMewanView Answer on Stackoverflow
Solution 11 - MysqlJamil NoydaView Answer on Stackoverflow
Solution 12 - MysqlYousef AltafView Answer on Stackoverflow
Solution 13 - MysqlRanieri MachadoView Answer on Stackoverflow
Solution 14 - Mysqluser3857472View Answer on Stackoverflow
Solution 15 - Mysqlsms247View Answer on Stackoverflow
Solution 16 - MysqldlandView Answer on Stackoverflow
Solution 17 - MysqlPrakash LakharaView Answer on Stackoverflow
Solution 18 - MysqlRP McMurphyView Answer on Stackoverflow