我正在尝试调试一些webapp的登录问题。
这里我在db机器上授予权限:
mysql> grant all on *.* to 'thruser'@'%' identified by 'a78jdv';
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for 'thruser';
+----------------------------------------------------------------------------------------+
| Grants for thruser@% |
+----------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'thruser'@'%' IDENTIFIED BY PASSWORD '0c4ab18e7adb7f20' |
+----------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
现在我转到Web服务器(IP 10.0.0.18,10.0.0.19是数据库服务器),然后尝试
$ mysql -u thruser --password=a78jdv -h 10.0.0.19
ERROR 1045 (28000): Access denied for user 'thruser'@'web01.e.nsoi.dk' (using password: YES)
这不起作用 - 虽然为什么?
现在,回到db机器上,尝试一些不同的东西:
mysql> drop user 'thruser'@'%';
Query OK, 0 rows affected (0.02 sec)
mysql> grant all on *.* to 'thruser'@'10.0.0.18' identified by 'a78jdv';
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for 'thruser'@'10.0.0.18';
+----------------------------------------------------------------------------------------------------+
| Grants for thruser@10.0.0.18 |
+----------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'thruser'@'10.0.0.18' IDENTIFIED BY PASSWORD '0c4ab18e7adb7f20' |
+----------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
再次转到Web服务器,并运行与上次相同的命令:
$ mysql -u thruser --password=a78jdv -h 10.0.0.19
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 178977
Server version: 5.1.51-community-log MySQL Community Server (GPL)
...
发生了什么事?为什么会
grant all on *.* to 'thruser'@'%' identified by 'a78jdv';
不起作用 - 主机部分是通配符,应该表示任何/所有主机,而
grant all on *.* to 'thruser'@'10.0.0.18' identified by 'a78jdv';
有用吗?
(我已经通过发布FLUSH PRIVILEGES再次完成此操作;在所有grant
之后,但结果相同)
答案 0 :(得分:1)
你有另一个名为'thruser'的用户,比如'thruser'@'localhost'吗?
如果是这样,请删除此本地用户,因为'%'在您的'web01.e.nsoi.dk'之前与您的localhost匹配。
更多信息here