10

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

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

它显示错误为,

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

在我读完这个之后

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

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

    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)

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

4

3 回答 3

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

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

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.

您正在寻找 DROP USER。

DROP USER user [, user] ...

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


业务顺序为:

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

如果您使用 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'];

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

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

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

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


请阅读这些错误报告以进一步澄清

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

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

于 2013-09-02T07:41:21.960 回答
2

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

删除用户'用户'@'本地主机'

于 2015-01-23T21:01:57.490 回答
0
select User, Host from mysql.user;

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

于 2016-10-08T20:06:02.200 回答