Experiences on the Front Lines of User Interfaces and Web Development

Fixing MySQL error when trying to drop a database

If you ever get the following error when trying to drop a table (or perhaps when running rake test in an Rails app):
Mysql::Error: Error dropping database (can't rmdir './app_test/', errno: 17): DROP DATABASE IF EXISTS `app_test`

Most likely your mysql server was killed or shutdown without properly cleaning up files. The error message is helpful, since it says it can not remove the directory "rr_test" (which is the name of my database table). The reason is because the directory is not empty.

1. Find the location of that table. For me on my Mac OS X 10.6 Snow Leopard, it was here:
/usr/local/mysql/data/app_test

2. View the file, and remove the file(s) - note the data directory is probably owned by root or a mysql group, so you will probably have to sudo to see or remove anything from it
> cd /usr/local/mysql
> sudo ls data/rr_test
> sudo rm data/rr_test/TEMP_FILE_THAT_DIDNT_GET_CLEANED_UP~


3. Confirm the directly is empty:
> sudo ls data/rr_test


4. Now try the command again and it should work!
mysql> drop database rr_test;
comments powered by Disqus