ERROR 1396 (HY000): Operation DROP USER failed for ‘user2’@’localhost’
While executing the drop command I am getting the following error:
MariaDB [(none)]> drop user user2@'localhost';
ERROR 1396 (HY000): Operation DROP USER failed for 'user2'@'localhost'
Cause: On checking the user table in MySQL getting the following information, we are using the wrong host in command.
MariaDB [(none)]> select user,host from mysql.user;
+-------------+----------------+
| User | Host |
+-------------+----------------+
| TEST | % |
| TEST1 | % |
| hr2 | % |
| user2 | % |
While the user is created as a ‘%’ host, you are using localhost while deleting the user. Modifying the query will fix the issue.
drop user user2@'%';
Example:
MariaDB [(none)]> drop user user2@'%';
Query OK, 0 rows affected (0.011 sec)