2

我创建了用户 'wordpress' 并通过 phpMyAdmin 在 mysql 上授予权限。但是,当我以用户 wordpress 在命令行登录时,我似乎无法访问我应该能够访问的内容。看一看:

>mysql -u wordpress
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.27 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SHOW GRANTS;
+--------------------------------------+
| Grants for @localhost                |
+--------------------------------------+
| GRANT USAGE ON *.* TO ''@'localhost' |
+--------------------------------------+
1 row in set (0.00 sec)

这不应该显示Grants for wordpress@localhost吗?

此外,我授予了所有(危险的,我知道,但我在进行健全性测试)在 datbase sitedb 上的 wordpress 特权。当我尝试使用 sitedb 时,我得到以下信息(这个,在同一个会话中):

mysql> USE sitedb;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'sitedb'

这是怎么回事?

4

3 回答 3

0

创建 mysql 用户时似乎出现了一些错误,我建议您从终端创建用户并授予权限。

于 2012-12-22T04:51:19.370 回答
0

来自MySQL文档:

USAGE 特权说明符代表“无特权”。</p>

您的用户似乎没有正确的权限。您确定您为正确的数据库授予了正确用户的所有权限吗?尝试仅将所有权限专门授予 sitedb 数据库。

于 2012-12-22T04:57:32.983 回答
0

我想到了...

我以 root 身份登录并检查了 root 的权限以及它与 wordpress 的不同之处:

mysql> SHOW GRANTS;
+---------------------------------------------------------------------+
| Grants for root@localhost                                           |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION        |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql> SHOW GRANTS FOR wordpress;
+-----------------------------------------------------------------------------+
| Grants for wordpress@%                                                      |
+-----------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'wordpress'@'%' WITH GRANT OPTION            |
| GRANT ALL PRIVILEGES ON `skytreader`.* TO 'wordpress'@'%' WITH GRANT OPTION |
+-----------------------------------------------------------------------------+
2 rows in set (0.00 sec)

就目前而言,我能收集到的唯一区别是主机。我回到 phpMyAdmin 更改用户 wordpress 的主机并将其指定为“localhost”。瞧,

>mysql -u wordpress
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 42
Server version: 5.5.27 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SHOW GRANTS;
+-------------------------------------------------------------------------------------+
| Grants for wordpress@localhost                                                      |
+-------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'wordpress'@'localhost' WITH GRANT OPTION            |
| GRANT ALL PRIVILEGES ON `skytreader`.* TO 'wordpress'@'localhost' WITH GRANT OPTION |
+-------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql> USE sitedb;
Database changed

现在我想知道为什么会这样?'wordpress'@'%' 不应该代表通配符主机(因此它应该包括 localhost)吗?我猜这是某种安全功能...

于 2012-12-22T05:19:45.247 回答