MySQL - 授予访问权限不起作用

时间:2015-03-20 21:40:43

标签: mysql mariadb

我正在尝试为mysql中的特定数据库授予用户访问权限。但命令似乎没有生效。

这就是我的意思:

第1步:

  • 创建db' testdb'
  • 授予' dummyuser' @'%'在testbd。*
  • 尝试使用testdb用户(FAILS)
  • 访问mysql

root @ bnode1 /] #mysql -h 172.22.191.202 -u root -ppassword

MariaDB [(none)]> 
MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS testdb;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all privileges on testdb.* to 'dummyuser'@'%'   identified by 'password';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye
[root@bnode1 /]# 
[root@bnode1 /]# mysql -h 172.22.191.202 -u dummyuser -ppassword
ERROR 1045 (28000): Access denied for user 'dummyuser'@'bnode1' (using   password: YES)

在mysql数据库中,我可以看到dummyuser的授权权限,如下所示:

MariaDB [(none)]> show grants for 'dummyuser';
+-----------------------------------------+
| Grants for dummyuser@%                                                                                        |
+-----------------------------------------+
| GRANT USAGE ON *.* TO 'dummyuser'@'%' IDENTIFIED BY PASSWORD     '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' |
| GRANT ALL PRIVILEGES ON `testdb`.* TO 'dummyuser'@'%'                                                   |
+-----------------------------------------+
2 rows in set (0.00 sec)

第2步: 现在我尝试了另一件事。授予用户' dummyuser' @' bnode1', 相同的命令,现在我可以访问。

root@bnode1 /]# mysql -h 172.22.191.202 -u root -ppassword     
Welcome to the MariaDB monitor.  Commands end with ; or \g.
...

MariaDB [(none)]> grant all privileges on testdb.* to '**dummyuser'@'bnode1'** identified by 'passwor>
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye
[root@bnode1 /]# 
[root@bnode1 /]# 
[root@bnode1 /]# mysql -h 172.22.191.202 -u dummyuser -ppassword
Welcome to the MariaDB monitor.  Commands end with ; or \g.
...
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

我不是mysql的专家,有人可以向我解释我做错了什么。

1 个答案:

答案 0 :(得分:1)

  

ERROR 1045(28000):拒绝用户访问' dummyuser' @' bnode1' (使用密码:是)

您可能需要尝试从其他主机进行连接,以查看' bnode1'限制为' dummyuser'

或者你可以创建一个新用户(因为你没有显示创建用户命令,我认为它是现有用户),你所做的grant命令应该可以工作。

不太可能,但为了以防万一,您需要确保' bind = 0.0.0.0'在my.cnf。

相关问题