macos MySQL 出现 DROP USER;但用户仍然存在于 mysql.users 表中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4817226/
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-10-21 07:39:46  来源:igfitidea点击:

MySQL appears to DROP USER; but user still exists in mysql.users table

mysqldatabasemacososx-snow-leopardmysql5

提问by ProcessEight

I've just installed MySQL Community server (5.5.8) on Mac OS X 10.6.6.

我刚刚在 Mac OS X 10.6.6 上安装了 MySQL 社区服务器 (5.5.8)。

I've been following the rules for a secure install (assign password to root, delete anonymous accounts, etc), however, there is one user account which I can't DROP:

我一直在遵循安全安装​​的规则(为 root 分配密码、删除匿名帐户等),但是,有一个我无法删除的用户帐户:

mysql> select host, user from mysql.user;
+--------------------------------+------+
| host                           | user |
+--------------------------------+------+
| 127.0.0.1                      | root |
| ::1                            | root |
| My-Computer-Hostname.local     |      |
| My-Computer-Hostname.local     | root |
| localhost                      | root |
| localhost                      | web  |
+--------------------------------+------+
6 rows in set (0.00 sec)

mysql> drop user ''@'My-Computer-Hostname.local';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> select host, user from mysql.user;
+--------------------------------+------+
| host                           | user |
+--------------------------------+------+
| 127.0.0.1                      | root |
| ::1                            | root |
| My-Computer-Hostname.local     |      |
| My-Computer-Hostname.local     | root |
| localhost                      | root |
| localhost                      | web  |
+--------------------------------+------+
6 rows in set (0.00 sec)

mysql> 

As you can see, MySQL reports no errors when executing the DROP USER command, but doesn't actually delete the user!

如您所见,MySQL 在执行 DROP USER 命令时没有报告错误,但实际上并没有删除用户!

I've tried also deleting the user from within phpMyAdmin (3.3.9) and that produced the same results (i.e. reported success, no error messages, user not deleted).

我也试过从 phpMyAdmin (3.3.9) 中删除用户并产生相同的结果(即报告成功,没有错误消息,用户未删除)。

I've researched this and some people suggest that GRANT may be blocking the DROP USER command, however, the user has no GRANT privileges:

我对此进行了研究,有些人认为 GRANT 可能会阻止 DROP USER 命令,但是,该用户没有 GRANT 权限:

mysql> SHOW GRANTS FOR ''@'My-Computer-Hostname.local';
+-----------------------------------------------------------+
| Grants for @my-computer-hostname.local                |
+-----------------------------------------------------------+
| GRANT USAGE ON *.* TO ''@'my-computer-hostname.local' |
+-----------------------------------------------------------+
1 row in set (0.00 sec)

mysql> REVOKE GRANT OPTION ON *.* FROM ''@'My-Computer-Hostname.local';
ERROR 1141 (42000): There is no such grant defined for user '' on host 'my-computer-hostname.local'

I tried dropping the user again after that but it didn't drop/delete the user either.

之后我再次尝试删除用户,但它也没有删除/删除用户。

I've checked my MySQl error logs and there's nothing unusual in there.

我检查了我的 MySQl 错误日志,里面没有任何异常。

The MySQL manual suggests that it is possible to delete all anonymous accounts, so why can't I delete this one?

MySQL 手册建议可以删除所有匿名帐户,那么为什么我不能删除这个?

采纳答案by Wim Deblauwe

This is a known bug due to your uppercase characters: http://bugs.mysql.com/bug.php?id=62255

由于您的大写字符,这是一个已知错误:http: //bugs.mysql.com/bug.php?id=62255

Use the suggestion from user douger as a workaround

使用用户 douger 的建议作为解决方法

回答by douger

Or, to delete just the anonymous one and not the root as well:

或者,只删除匿名的而不是根:

mysql> DELETE FROM mysql.user WHERE User='' AND Host='my-computer-hostname.local';

mysql> DELETE FROM mysql.user WHERE User='' AND Host='my-computer-hostname.local';

Worked for me on 5.1.57.

在 5.1.57 上对我来说有效。

回答by Jeroen Snijders

You can still delete the records from the user table:

您仍然可以从用户表中删除记录:

mysql> DELETE FROM user WHERE host='my-computer-hostname.local';
Query OK, 2 rows affected (0.00 sec)

mysql> DELETE FROM user WHERE host='my-computer-hostname.local';
Query OK, 2 rows affected (0.00 sec)

This method was used prior to MySQL 4.1...

该方法在 MySQL 4.1 之前使用...

回答by mohlatif227

MySQL includes an anonymous user account that allows anyone to connect into the MySQL server without having a user account. This is meant only for testing, and should be removed before the database server is put into a production environment.

MySQL 包含一个匿名用户帐户,允许任何人在没有用户帐户的情况下连接到 MySQL 服务器。这仅用于测试,应在将数据库服务器放入生产环境之前将其删除。

Run the following SQL script against the MySQL server to remove the anonymous user account:

针对 MySQL 服务器运行以下 SQL 脚本以删除匿名用户帐户:

DELETE FROM mysql.user WHERE User='';

After making changes to permissions/user accounts, make sure you flush the provilege tables using the following command:

更改权限/用户帐户后,请确保使用以下命令刷新权限表:

FLUSH PRIVILEGES;