Bug #67823 drop user return success but do not delete record at all
Submitted: 6 Dec 2012 9:20 Modified: 6 Jan 2013 17:54
Reporter: lou shuai (OCA) Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:5.5.* 5.6.* OS:Any
Assigned to: CPU Architecture:Any
Tags: drop user, flush privileges

[6 Dec 2012 9:20] lou shuai
Description:
Bug #62255 already issue this problem, but not the whole thing.

Every 'drop user' after 'flush privileges' will return success but do not delete record in mysql.user at all.

But the second time we execute 'drop user' will return error.

How to repeat:
mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| repl | %         |
| u1   | %         |
| root | 127.0.0.1 |
| root | ::1       |
|      | Ubuntu    |
| root | Ubuntu    |
|      | localhost |
| root | localhost |
+------+-----------+
8 rows in set (0.04 sec)

mysql> drop user ''@'Ubuntu';
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| repl | %         |
| u1   | %         |
| root | 127.0.0.1 |
| root | ::1       |
|      | Ubuntu    |
| root | Ubuntu    |
|      | localhost |
| root | localhost |
+------+-----------+
8 rows in set (0.00 sec)

mysql> drop user ''@'Ubuntu';
ERROR 1396 (HY000): Operation DROP USER failed for ''@'ubuntu'

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> drop user ''@'Ubuntu';
Query OK, 0 rows affected (31 min 17.41 sec)

mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| repl | %         |
| u1   | %         |
| root | 127.0.0.1 |
| root | ::1       |
|      | Ubuntu    |
| root | Ubuntu    |
|      | localhost |
| root | localhost |
+------+-----------+
8 rows in set (0.00 sec)

Suggested fix:
Bug #62255 at last give a Minimal fix, but it just make sure all host is low-case after we install a new database.
Actually it is the function handle_grant_data need to be modified.

org code:
 /* Handle user table. */
  if ((found= handle_grant_table(tables, 0, drop, user_from, user_to)) < 0)
  {
    /* Handle of table failed, don't touch the in-memory array. */
    result= -1;
  }
modified code:
/* Handle user table. */
  if ((found= handle_grant_table(tables, 0, drop, user_from, user_to)) <= 0)
  {
    /* Handle of table failed, don't touch the in-memory array. */
    result= found < 0 ? -1 : 0;
  }

Actually if there is error or no record matched, we should not deal with in-memory structs, am i right ?
[6 Dec 2012 17:54] Sveta Smirnova
Thank you for the report.

I don't see why this case is different from bug #62255: in that bug problem only exists for hosts with uppercase letters and for this one too. Please explain.
[7 Jan 2013 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".