@@ -784,7 +784,7 @@ bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info)
784
784
bool mysql_rm_db (THD *thd,char *db,bool if_exists, bool silent)
785
785
{
786
786
ulong deleted_tables= 0 ;
787
- bool error= true ;
787
+ bool error= true , rm_mysql_schema ;
788
788
char path[FN_REFLEN + 16 ];
789
789
MY_DIR *dirp;
790
790
uint length;
@@ -809,6 +809,18 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
809
809
length= build_table_filename (path, sizeof (path) - 1 , db, " " , " " , 0 );
810
810
strmov (path+length, MY_DB_OPT_FILE); // Append db option file name
811
811
del_dbopt (path); // Remove dboption hash entry
812
+ /*
813
+ Now remove the db.opt file.
814
+ The 'find_db_tables_and_rm_known_files' doesn't remove this file
815
+ if there exists a table with the name 'db', so let's just do it
816
+ separately. We know this file exists and needs to be deleted anyway.
817
+ */
818
+ if (my_delete_with_symlink (path, MYF (0 )) && my_errno != ENOENT)
819
+ {
820
+ my_error (EE_DELETE, MYF (0 ), path, my_errno);
821
+ DBUG_RETURN (true );
822
+ }
823
+
812
824
path[length]= ' \0 ' ; // Remove file name
813
825
814
826
/* See if the directory exists */
@@ -835,7 +847,8 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
835
847
Disable drop of enabled log tables, must be done before name locking.
836
848
This check is only needed if we are dropping the "mysql" database.
837
849
*/
838
- if ((my_strcasecmp (system_charset_info, MYSQL_SCHEMA_NAME.str , db) == 0 ))
850
+ if ((rm_mysql_schema=
851
+ (my_strcasecmp (system_charset_info, MYSQL_SCHEMA_NAME.str , db) == 0 )))
839
852
{
840
853
for (table= tables; table; table= table->next_local )
841
854
if (check_if_log_table (table, TRUE , " DROP" ))
@@ -848,7 +861,7 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
848
861
lock_db_routines (thd, dbnorm))
849
862
goto exit;
850
863
851
- if (!in_bootstrap)
864
+ if (!in_bootstrap && !rm_mysql_schema )
852
865
{
853
866
for (table= tables; table; table= table->next_local )
854
867
{
@@ -893,10 +906,13 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
893
906
ha_drop_database (path);
894
907
tmp_disable_binlog (thd);
895
908
query_cache_invalidate1 (thd, dbnorm);
896
- (void ) sp_drop_db_routines (thd, dbnorm); /* @todo Do not ignore errors */
909
+ if (!rm_mysql_schema)
910
+ {
911
+ (void ) sp_drop_db_routines (thd, dbnorm); /* @todo Do not ignore errors */
897
912
#ifdef HAVE_EVENT_SCHEDULER
898
- Events::drop_schema_events (thd, dbnorm);
913
+ Events::drop_schema_events (thd, dbnorm);
899
914
#endif
915
+ }
900
916
reenable_binlog (thd);
901
917
902
918
/*
0 commit comments