
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Solve ERROR 1396 (HY000): Operation DROP USER failed for 'user'@'localhost' in MySql?
This error occurs when you drop a user with localhost while you have created a user with ‘%’.
Let us create a user with ‘%’ and drop the user as a localhost. The syntax is as follows
CREATE USER 'yourUserName'@'%' IDENTIFIED BY 'yourPassword';
Let us create a user using the above syntax. The query to create a user is as follows
mysql> CREATE USER 'Jack'@'%' IDENTIFIED BY '1234'; Query OK, 0 rows affected (0.26 sec)
Check user is created successfully or not
mysql> select user,host from MySQL.user;
The following is the output
+------------------+-----------+ | user | host | +------------------+-----------+ | Jack | % | | Manish | % | | User2 | % | | mysql.infoschema | % | | mysql.session | % | | mysql.sys | % | | root | % | | Adam Smith | localhost | | User1 | localhost | | am | localhost | +------------------+-----------+ 10 rows in set (0.00 sec)
Look at the above sample output, we have a user with name ‘Jack’ and host is ‘%’. Whenever you try to drop the user with localhost then you will get an error which is as follows
mysql> DROP USER 'Jack'@'localhost'; ERROR 1396 (HY000): Operation DROP USER failed for 'Jack'@'localhost'
Let us drop the above user with host ‘%’. The query is as follows
mysql> DROP USER 'Jack'@'%'; Query OK, 0 rows affected (0.19 sec)
Check the user has been dropped or not from MySQL.user table. The query is as follows
mysql> select user,host from MySQL.user;
The following is the output displaying that the user Jack is removed successfully
+------------------+-----------+ | user | host | +------------------+-----------+ | Manish | % | | User2 | % | | mysql.infoschema | % | | mysql.session | % | | mysql.sys | % | | root | % | | Adam Smith | localhost | | User1 | localhost | | am | localhost | +------------------+-----------+ 9 rows in set (0.00 sec)
- Related Articles
- ERROR 1396 (HY000): Operation CREATE USER failed for 'root'@'localhost'?
- Fix: ERROR 1396 (HY000): Operation CREATE USER failed in MySQL?
- MySQL appears to DROP USER but user still exists in MySQL.users table?
- Resolve error 1045 (28000) access denied for user 'root'@'localhost' (using password: YES)?
- Check if a user exists in MySQL and drop it?
- How to update User Logged in Time for a specific user in MySQL?
- Display all grants for user in MySQL
- Check privileges (grants) for a specific user in MySQL?
- How to display grant defined for a MySQL user?
- Using User-Defined Variables in MySQL
- Can we use the word user for a MySQL table?
- User Requirement and User Story in Agile
- How can we change MySQL user password by using the ALTER USER statement?
- MySQL CREATE USER with a variable?
- What do you mean by default MySQL database for the user?

Advertisements