我似乎无法重新创建一个我已经删除的简单用户,即使是MySQL的根用户。

我的案例:用户'jack'之前存在,但我从mysql中删除了它。用户才能重新创建它。我在那张桌子上没看到这东西的痕迹。如果我对其他一些随机用户名执行这个命令,比如'jimmy',它就能正常工作(就像它最初对'jack'所做的那样)。

我做了什么破坏用户'jack',我如何撤销这个破坏,以重新创建'jack'作为MySQL安装的有效用户?

参见下面的示例。(当然,最初,jack这个词从被创造到被移除之间有很长一段时间。)

mysql> CREATE USER 'jack'@'localhost' IDENTIFIED BY 'test123';
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host from user;
+------------------+-----------------+
| user             | host            |
+------------------+-----------------+
| root             | 127.0.0.1       |
| debian-sys-maint | localhost       |
| jack             | localhost       |
| root             | localhost       |
| root             | russ-elite-book |
+------------------+-----------------+
5 rows in set (0.00 sec)

mysql> delete from user where user = 'jack';
Query OK, 1 row affected (0.00 sec)

mysql> select user,host from user;
+------------------+-----------------+
| user             | host            |
+------------------+-----------------+
| root             | 127.0.0.1       |
| debian-sys-maint | localhost       |
| root             | localhost       |
| root             | russ-elite-book |
+------------------+-----------------+
4 rows in set (0.00 sec)

mysql> CREATE USER 'jack'@'localhost' IDENTIFIED BY 'test123';
ERROR 1396 (HY000): Operation CREATE USER failed for 'jack'@'localhost'
mysql> CREATE USER 'jimmy'@'localhost' IDENTIFIED BY 'test123';
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host from user;
+------------------+-----------------+
| user             | host            |
+------------------+-----------------+
| root             | 127.0.0.1       |
| debian-sys-maint | localhost       |
| jimmy            | localhost       |
| root             | localhost       |
| root             | russ-elite-book |
+------------------+-----------------+
5 rows in set (0.00 sec)

当前回答

删除用户,刷新权限;然后,创建用户。它确实有效!

其他回答

您不应该以这种方式手动删除用户。MySQL有REVOKE语法用来删除权限,DROP USER语法用来删除权限:

REVOKE priv1,priv2,priv3,etc... FROM 'jack@localhost'; // remove certain privileges
DROP USER 'jack@localhost'; // completely delete the account

最好使用提供的工具,而不是在后台瞎忙活。

是的,这个bug就在那里。然而,我找到了一个小小的变通办法。

假设用户在那里,那么删除用户 删除用户后,需要刷新mysql权限 现在创建用户。

这应该能解决问题。假设我们要创建admin @ localhost用户,下面的命令如下:

drop user admin@localhost;
flush privileges;
create user admin@localhost identified by 'admins_password'

我和OP有同样的问题,接受的答案不适合我。在接受答案的评论中,@Rathish发布了一个对我有用的解决方案,我想引起大家的注意。

这是链接:

https://www.rathishkumar.in/2018/10/Error-1396-HY000-Operation-CREATE-DROP-USER-failed-for-user-host.html

Rathish的解决方案是撤销所有用户的访问权限:

REVOKE ALL ON *.* FROM 'user'@'host';
DROP USER 'user'@'host';
FLUSH PRIVILEGES;

他还很有帮助地指出,你可以通过选择“user”和“host”来查询下面的表格,以确定你是否有之前操作留下的残留用户:

mysql.user: User accounts, global privileges, and other non-privilege columns
mysql.db: Database-level privileges
mysql.tables_priv: Table-level privileges
mysql.columns_priv: Column-level privileges
mysql.procs_priv: Stored procedure and function privileges
mysql.proxies_priv: Proxy-user privilege

谢谢你!

MySql的错误解决:错误码1396

Whenever you had try to run query which create a User as Shown Below. MySql> CREATE USER 'springstudent'@'localhost' IDENTIFIED BY 'springstudent'; GRANT ALL PRIVILEGES ON * . * TO 'springstudent'@'localhost'; But when you try to run query which create user within all previleges, Due to bug it create gives previleges without showing user Because of this Problem we need to use this script for flush priviledges MySql> drop user 'springstudent'@'localhost'; flush privileges; create user admin@localhost identified by 'admins_password' After deleting the user, there is need to flush the mysql privileges Then Create User again

Gotchaaa ....Solved ....

two method 
one :
setp 1: drop user 'jack'@'localhost';
setp 2: create user 'jack'@localhost identified by 'ddd';

two:
setp 1: delete from user where user='jack'and host='localhost';
setp 2: flush privileges;
setp 3: create user 'jack'@'localhost' identified by 'ddd';