在 mysql 错误 1396 (HY000) 中创建和删除用户时:操作 CREATE USER

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18567118/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:42:56  来源:igfitidea点击:

while creating and deleting user in mysql ERROR 1396 (HY000): Operation CREATE USER

mysql

提问by saravanakumar

I am trying to create new user in mysql,

我正在尝试在 mysql 中创建新用户,

    create user 'saravanakumar'@'localhost' identified by 'saravanakumar';

it shows error as,

它显示错误为,

    ERROR 1396 (HY000): Operation CREATE USER failed for 'saravanakumar'@'localhost'

after I read this

在我读完这篇文章之后

ERROR 1396 (HY000): Operation CREATE USER failed for 'Hyman'@'localhost'

错误 1396 (HY000):操作 CREATE USER 对 'Hyman'@'localhost' 失败

I delete user.But I can't.It shows

我删除用户。但我不能。它显示

    mysql> SELECT User FROM mysql.user;
    +---------------+
    | User          |
    +---------------+
    | root          |
    | saravanakumar |
    | saravanakumar |
    |               |
    | root          |
    | saravanakumar |
    |               |
    | root          |
    +---------------+
    8 rows in set (0.00 sec)

    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.00 sec)

    mysql> SELECT User FROM mysql.user;
    +---------------+
    | User          |
    +---------------+
    | root          |
    | saravanakumar |
    | saravanakumar |
    |               |
    | root          |
    | saravanakumar |
    |               |
    | root          |
    +---------------+
    8 rows in set (0.00 sec)

how can i delete all these user in table and how can i create a single user.What is the root cause of this problem? experts please help me.

如何删除表中的所有这些用户以及如何创建单个用户。此问题的根本原因是什么?请专家帮助我。

回答by Xevelion

ERROR 1396 (HY000): Operation CREATE USER failed for 'saravanakumar'@'localhost'

Does indeed indicate that the user already exists or did exist.

确实表明用户已经存在或确实存在。

FLUSH PRIVILEGES doesn't delete users.

FLUSH PRIVILEGES 不会删除用户。

Reloads the privileges from the grant tables in the mysql database.

The server caches information in memory as a result of GRANT, CREATE USER, 
CREATE SERVER, and INSTALL PLUGIN statements. This memory is not released 
by the corresponding REVOKE, DROP USER, DROP SERVER, and UNINSTALL PLUGIN 
statements, so for a server that executes many instances of the statements 
that cause caching, there will be an increase in memory use. 
This cached memory can be freed with FLUSH PRIVILEGES.

You are looking for DROP USER.

您正在寻找 DROP USER。

DROP USER user [, user] ...

http://dev.mysql.com/doc/refman/5.1/en/drop-user.html

http://dev.mysql.com/doc/refman/5.1/en/drop-user.html



Order of buisness would be:

业务顺序是:

DROP USER 'saravanakumar'@HOSTNAME;
CREATE USER 'saravanakumar'@HOSTNAME [IDENTIFIED BY 'password'];


You will probably need to flush privileges if you use delete from (do not). Remember: this does not necessarily revoke all the privileges this user may have (like table privileges), you will have to do this yourself - if you don't you may not be able to recreate the user.

如果您使用 delete from(不要),您可能需要刷新权限。 请记住:这不一定会撤销该用户可能拥有的所有权限(如表权限),您必须自己执行此操作 -如果不这样做,您可能无法重新创建该用户

REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'saravanakumar'@HOSTNAME;
DELETE FROM mysql.user WHERE user='saravanakumar';
FLUSH PRIVILEGES;
CREATE USER 'saravanakumar'@HOSTNAME [IDENTIFIED BY 'password'];


"user" requires you to specify an account name

“用户”要求您指定帐户名称

Syntax for account names is 'user_name'@'host_name'

and

An account name consisting only of a user name is equivalent 
to 'user_name'@'%'. For example, 'me' is equivalent to 'me'@'%'.

Additional reading: http://dev.mysql.com/doc/refman/5.1/en/account-names.html

补充阅读:http: //dev.mysql.com/doc/refman/5.1/en/account-names.html



Please read those bug reports for further clarification

请阅读这些错误报告以进一步说明

http://bugs.mysql.com/bug.php?id=28331

http://bugs.mysql.com/bug.php?id=28331

http://bugs.mysql.com/bug.php?id=62255

http://bugs.mysql.com/bug.php?id=62255

回答by Luferquisa

To me works, I set hostname in UPPERCASE:

对我来说,我将主机名设置为大写:

DROP USER 'user'@'LOCALHOST'

删除用户 'user'@'LOCALHOST'

回答by user1960812

select User, Host from mysql.user;

Made it clear for me what was happening. I had ended up with the same user under several hosts. Deleting unwanted ones helped!

让我清楚地知道发生了什么。我最终在几个主机下使用了同一个用户。删除不需要的帮助!