Bienvenido! - Willkommen! - Welcome!

Bitácora Técnica de Tux&Cía., Santa Cruz de la Sierra, BO
Bitácora Central: Tux&Cía.
Bitácora de Información Avanzada: Tux&Cía.-Información
May the source be with you!

Tuesday, November 30, 2010

'Can't drop database ''; database doesn't exist'

ERROR 1008 (HY000)
error: 'Can't drop database 'test'; database doesn't exist' 
Remark:
does the OS user you use to execute mysql have create/write/read/execute
rights to the ./test folder?
Mysql ressources IF EXISTS is used to prevent an error from occurring if the database does not exist.
If the default database is dropped, the default database is unset (the DATABASE() function returns NULL).
If you use DROP DATABASE on a symbolically linked database, both the link and the original database are deleted.
DROP DATABASE returns the number of tables that were removed. This corresponds to the number of .frm files removed.
The DROP DATABASE statement removes from the given database directory those files and directories that MySQL itself may create during normal operation:
  • All files with the following extensions.
    .BAK .DAT .HSH .MRG
    .MYD .MYI .TRG .TRN
    .db .frm .ibd .ndb
  • All subdirectories with names that consist of two hex digits 00-ff. These are subdirectories used for RAID tables. (These directories are not removed as of MySQL 5.0, when support for RAID tables was removed. You should convert any existing RAID tables and remove these directories manually before upgrading to MySQL 5.0. See Section 2.19.1.2, “Upgrading from MySQL 4.1 to 5.0”.)
  • The db.opt file, if it exists.
If other files or directories remain in the database directory after MySQL removes those just listed, the database directory cannot be removed. In this case, you must remove any remaining files or directories manually and issue the DROP DATABASE statement again.
 
Source 
DROP DATABASE Statement 
Use this MySQL statement to delete a given database along with all its tables and data.
Statements
DROP {DATABASE|SCHEMA} [IF EXISTS] database
Explanation
Use this MySQL statement to delete a given database along with all its tables and data. The addition of the IF EXISTS flag suppresses an error message if the database does not already exist. You must have the DROP privilege for the database to be able to delete it in MySQL.
Examples
Here is an example of this MySQL statement's use:
DROP DATABASE IF EXISTS test;
Query OK, 6 rows affected (0.42 sec)
The number of tables in MySQL that have been deleted is returned in the rows affected count. If the database doesn't exist or if there are other files in the database's filesystem directory, an error message will be displayed. The tables will be deleted if other files exist, but the foreign file and the directory for the database won't be removed. They will have to be deleted manually at the command line using a filesystem command such as rm in Unix or del in Windows. Here's an example in which a foreign file is found in the database directory when dropping a database:
DROP DATABASE IF EXISTS test;

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

SHOW TABLES FROM test;
Empty set (0.00 sec)

SHOW DATABASES LIKE 'test';

+-----------------+
| Database (test) |
+-----------------+
| test            | 
+-----------------+
In this example, we've attempted to drop the database, but were unsuccessful because of a foreign file located in the database's directory at the filesystem level. The tables were all dropped as indicated from the results of the SHOW TABLES statement, but the database remains. After manually deleting the foreign file, we run the MySQL statement,DROP DATABASE again:
DROP DATABASE IF EXISTS test;
Query OK, 0 rows affected (0.43 sec)

DROP DATABASE test;

ERROR 1008 (HY000): Can't drop database 'test'; 
database doesn't exist
This time the statement was successful, as indicated by our extra attempt without the IF EXISTS flag. No tables were dropped by the second attempt because they were all deleted on the first attempt, so the number of rows affected was 0.
If a database is dropped, any user privileges specific to the database (e.g., privileges listed in the db table of the mysql database) are not automatically deleted. Therefore, if a database is later created with the same name, those user privileges will apply to the new database, a potential security risk.

No comments: