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 ?