Bug #82953 Server reports that database both exists and doesn't exist
Submitted: 12 Sep 2016 18:58 Modified: 13 Sep 2016 13:04
Reporter: Daniël van Eeden (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Errors Severity:S3 (Non-critical)
Version:8.0.0 OS:Any
Assigned to: CPU Architecture:Any

[12 Sep 2016 18:58] Daniël van Eeden
Description:
If I create a dir in @@global.datadir and then try to create or drop a database with the same name then the error messages are confusing.

How to repeat:
cd /mysql/db/data/
mkdir test_fs

root@dvaneeden-test-2002 [(none)]> \! find /mysql/db/data/ -type d
/mysql/db/data/
/mysql/db/data/mysql
/mysql/db/data/performance_schema
/mysql/db/data/sys
/mysql/db/data/generic
/mysql/db/data/employees
/mysql/db/data/test_fs
root@dvaneeden-test-2002 [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| employees          |
| generic            |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
6 rows in set (0.00 sec)

root@dvaneeden-test-2002 [(none)]> create schema test_fs;
ERROR 1007 (HY000): Can't create database 'test_fs'; database exists
root@dvaneeden-test-2002 [(none)]> drop schema test_fs;
ERROR 1008 (HY000): Can't drop database 'test_fs'; database doesn't exist
root@dvaneeden-test-2002 [(none)]> select version();
+---------------+
| version()     |
+---------------+
| 8.0.0-dmr-log |
+---------------+
1 row in set (0.00 sec)

Suggested fix:
Update the error messages to indicate that a directory with that name exists, but no database and that it is not possible to create the database. 

Like this:
root@dvaneeden-test-2002 [(none)]> create schema test_fs;
ERROR 1007 (HY000): Can't create database 'test_fs'; a directory already exists with that name.
root@dvaneeden-test-2002 [(none)]> drop schema test_fs;
ERROR 1008 (HY000): Can't drop database 'test_fs'; database doesn't exist
[13 Sep 2016 13:04] MySQL Verification Team
Hello Daniël,

Thank you for the report.

Thanks,
Umesh
[13 Sep 2016 13:05] MySQL Verification Team
-- 8.0

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

mysql> SYSTEM mkdir -p 82953/test_fs

mysql> SYSTEM ls -l 82953/test_fs
total 0
mysql> SYSTEM find  82953/test_fs -type d
82953/test_fs
mysql>
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

mysql> create schema test_fs;
ERROR 1007 (HY000): Can't create database 'test_fs'; database exists
mysql> drop schema test_fs;
ERROR 1008 (HY000): Can't drop database 'test_fs'; database doesn't exist
mysql>