Skip to content

Commit 26b87c3

Browse files
author
Alexey Botchkov
committed
MDEV-10846 Running mysqldump backup twice returns error: Table
'mysql.proc' doesn't exist. The mysql_rm_db() doesn't seem to expect the 'mysql' database to be deleted. Checks for that added. Also fixed the bug MDEV-11105 Table named 'db' has weird side effect. The db.opt file now removed separately.
1 parent 22490a0 commit 26b87c3

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

mysql-test/r/drop.result

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,9 @@ INSERT INTO table1 VALUES (1);
209209
ERROR 42S02: Unknown table 't.notable'
210210
DROP TABLE table1,table2;
211211
# End BUG#34750
212+
#
213+
# MDEV-11105 Table named 'db' has weird side effect.
214+
#
215+
CREATE DATABASE mysqltest;
216+
CREATE TABLE mysqltest.db(id INT);
217+
DROP DATABASE mysqltest;

mysql-test/t/drop.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,12 @@ INSERT INTO table1 VALUES (1);
313313
DROP TABLE table1,table2;
314314

315315
--echo # End BUG#34750
316+
317+
--echo #
318+
--echo # MDEV-11105 Table named 'db' has weird side effect.
319+
--echo #
320+
321+
CREATE DATABASE mysqltest;
322+
CREATE TABLE mysqltest.db(id INT);
323+
DROP DATABASE mysqltest;
324+

sql/sql_db.cc

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info)
784784
bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
785785
{
786786
ulong deleted_tables= 0;
787-
bool error= true;
787+
bool error= true, rm_mysql_schema;
788788
char path[FN_REFLEN + 16];
789789
MY_DIR *dirp;
790790
uint length;
@@ -809,6 +809,18 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
809809
length= build_table_filename(path, sizeof(path) - 1, db, "", "", 0);
810810
strmov(path+length, MY_DB_OPT_FILE); // Append db option file name
811811
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+
812824
path[length]= '\0'; // Remove file name
813825

814826
/* See if the directory exists */
@@ -835,7 +847,8 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
835847
Disable drop of enabled log tables, must be done before name locking.
836848
This check is only needed if we are dropping the "mysql" database.
837849
*/
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)))
839852
{
840853
for (table= tables; table; table= table->next_local)
841854
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)
848861
lock_db_routines(thd, dbnorm))
849862
goto exit;
850863

851-
if (!in_bootstrap)
864+
if (!in_bootstrap && !rm_mysql_schema)
852865
{
853866
for (table= tables; table; table= table->next_local)
854867
{
@@ -893,10 +906,13 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
893906
ha_drop_database(path);
894907
tmp_disable_binlog(thd);
895908
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 */
897912
#ifdef HAVE_EVENT_SCHEDULER
898-
Events::drop_schema_events(thd, dbnorm);
913+
Events::drop_schema_events(thd, dbnorm);
899914
#endif
915+
}
900916
reenable_binlog(thd);
901917

902918
/*

0 commit comments

Comments
 (0)