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

标签 mysql mariadb

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

我的意思是:

第一步:

  • 创建数据库'testdb'
  • 在 testbd 上授予 'dummyuser'@'%' 权限。*
  • 尝试使用 testdb 用户访问 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 专家,谁能给我解释一下我做错了什么。

最佳答案

ERROR 1045 (28000): Access denied for user 'dummyuser'@'bnode1' (using password: YES)

您可能需要尝试从其他主机连接以查看“bnode1”是否被“dummyuser”限制

或者您可以创建一个新用户(因为您没有显示创建用户命令,我假设它是一个现有用户)并且您执行的授权命令应该可以工作。

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

关于MySQL - 授予访问权限不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29176236/

相关文章:

java - Web 应用程序、离线模式和同步

php - MySQL PHP 图表

mysql - 在 django 模型中存储时区的假设?

php - 无法从 WAMP 登录 MySQL,但可以登录 MariaDB

python - 我应该将 Unix 时间存储在单独的表中吗

mysql - Docker 容器、内存消耗和日志

mysql - SQL中基于datediff和curdate函数计算列值

mysql,多列还是varchar列?

mysql join 选择两个表之间的最小(日期)和最大(日期)

mysql - Ecto 为 Mysql/Mariadb 创建唯一索引失败