GreatSQL社区

搜索

[已解决] 小白求助

677 9 2024-5-17 09:20
为啥建立角色后,对其授予了权限,但转接给用户,无法在用户上实现权限,语句如下:
create role Classmates;
Query OK, 0 rows affected (0.07 sec)

grant all privileges on Students to Classmates;
Query OK, 0 rows affected (0.01 sec)


grant select  on SC to Classmates;
Query OK, 0 rows affected (0.02 sec)


grant Classmates to Cjh,Fxk,Rjh;
Query OK, 0 rows affected (0.02 sec)

登入用户Rjh后

select * from SC;
ERROR 1142 (42000): SELECT command denied to user 'Rjh'@'localhost' for table 'sc'
mysql> select * from Students;
+-----------+-------+------+------------+------------+----------------------+------+
| Sno       | Sname | Sex  | Birthday   | Enrollyear | Speciality           | Dno  |
+-----------+-------+------+------------+------------+----------------------+------+
| 202200304 | Cjk   | 1    | 2004-02-28 | 2022       | Computer Techonology | CT   |
| 202200305 | Cwl   | 0    | 2004-03-18 | 2022       | Computer Techonology | CT   |
| 202200306 | Cjt   | 1    | 2004-02-15 | 2022       | Computer Techonology | CT   |
| 202201001 | Fxk   | 1    | 2004-02-28 | 2022       | math                 | MA   |
| 202201002 | Swt   | 0    | 2004-06-01 | 2022       | math                 | MA   |
| 202201003 | Rjh   | 1    | 2004-05-22 | 2022       | math                 | MA   |
| 202201007 | Cjh   | 1    | 2004-02-01 | 2022       | math                 | MA   |

只有查询Students可以实现(因为前面用root身份进行了授权),想查询SC表却无法做到,求助具体原因,感谢



全部回复(9)
yejr 2024-5-17 12:25:18
先执行
  1. show grants for Classmates
复制代码
以及
  1. show grants for Rjh
复制代码
确认最终授权结果。

另外,grant xx for Rjh 这种写法,等同于授权给 Rjh@%,但我看你后面执行select的账号是 Rjh@localhost,这二者不等价。
万里旅人 2024-5-17 15:03:21
[quote]yejr 发表于 2024-5-17 12:25
先执行  以及
  1. show grants for Rjh[code] 确认最终授权结果。

  2. 另外,grant xx for Rjh 这种写法,等 ...[/quote][code]
  3. mysql> show grants for Classmates;
  4. +---------------------------------------------------------------+
  5. | Grants for Classmates@%                                       |
  6. +---------------------------------------------------------------+
  7. | GRANT USAGE ON *.* TO `Classmates`@`%`                        |
  8. | GRANT SELECT ON `test`.`sc` TO `Classmates`@`%`               |
  9. | GRANT ALL PRIVILEGES ON `test`.`students` TO `Classmates`@`%` |
  10. +---------------------------------------------------------------+
  11. 3 rows in set (0.06 sec)

  12. mysql> show grants for Rjh;
  13. +--------------------------------------------------------------------------+
  14. | Grants for Rjh@%                                                         |
  15. +--------------------------------------------------------------------------+
  16. | GRANT USAGE ON *.* TO `Rjh`@`%`                                          |
  17. | GRANT USAGE ON `test`.`sc` TO `Rjh`@`%` WITH GRANT OPTION                |
  18. | GRANT ALL PRIVILEGES ON `test`.`students` TO `Rjh`@`%` WITH GRANT OPTION |
  19. | GRANT `Classmates`@`%` TO `Rjh`@`%`                                      |
  20. +--------------------------------------------------------------------------+
复制代码

查询结果如上,并未显示出具有对SC表的任何权限,但有角色与用户之间授予权限,想问一下这里没有实现角色权限转移实是因为MySQL中角色这块的实际应用不对吗?
yejr 2024-5-17 15:57:37
yejr 发表于 2024-5-17 12:25
先执行  以及  确认最终授权结果。

另外,grant xx for Rjh 这种写法,等同于授权给 Rjh@%,但我看你后面 ...

另外,grant xx for Rjh 这种写法,等同于授权给 Rjh@%,但我看你后面执行select的账号是 Rjh@localhost,这二者不等价。
====
看我这里的提醒,意思是不要用 Rjh@localhost 方式登入,改成 tcp/ip + 端口方式登入,例如

  1. mysql -h 127.0.0.1 -u Rjh -p x -P 3306
复制代码
万里旅人 2024-5-17 18:38:00
yejr 发表于 2024-5-17 15:57
另外,grant xx for Rjh 这种写法,等同于授权给 Rjh@%,但我看你后面执行select的账号是 Rjh@localhost ...

  1. [root@localhost ~]# /usr/local/GreatSQL-8.0.32-25-Linux-glibc2.17-x86_64-minimal/bin/mysql -h 127.0.0.1 -u Rjh -pCjh200421@ -P 3306
  2. mysql: [Warning] Using a password on the command line interface can be insecure.
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.
  4. Your MySQL connection id is 14
  5. Server version: 8.0.32-25 GreatSQL, Release 25, Revision db07cc5cb73

  6. Copyright (c) 2021-2023 GreatDB Software Co., Ltd
  7. Copyright (c) 2009-2023 Percona LLC and/or its affiliates
  8. Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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

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

  13. mysql> use test;
  14. Reading table information for completion of table and column names
  15. You can turn off this feature to get a quicker startup with -A

  16. Database changed
  17. mysql> select * from SC;
  18. ERROR 1142 (42000): SELECT command denied to user 'Rjh'@'localhost' for table 'sc'
  19. mysql> select user();
  20. +---------------+
  21. | user()        |
  22. +---------------+
  23. | Rjh@localhost |
  24. +---------------+
  25. 1 row in set (0.01 sec)
复制代码

采用这种登入方式,但用户还是没变,这个是为啥呀?
reddey 2024-5-17 20:33:44
万里旅人 发表于 2024-5-17 18:38
[root@localhost ~]# /usr/local/GreatSQL-8.0.32-25-Linux-glibc2.17-x86_64-minimal/bin/mysql -h 127. ...

grant Classmates to 'Rjh'@'localhost'这样授权,看看行不行。
一个学艺不精的国产数据库爱好者
reddey 2024-5-17 20:48:28
grant all privileges on Students to Classmates;这个语句授权有问题吧,ON后面就是数据库名.表名吧
一个学艺不精的国产数据库爱好者
yejr 2024-5-18 07:50:19
万里旅人 发表于 2024-5-17 18:38
[root@localhost ~]# /usr/local/GreatSQL-8.0.32-25-Linux-glibc2.17-x86_64-minimal/bin/mysql -h 127. ...

感觉你的操作还是哪里有问题,你看看我的就正常

  1. # mysql -h127.0.0.1 -uyejr -pyejr -P3306
  2. mysql: [Warning] Using a password on the command line interface can be insecure.
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.
  4. Your MySQL connection id is 1990455
  5. Server version: 8.0.32-25 GreatSQL, Release 25, Revision 79f57097e3f

  6. Copyright (c) 2021-2023 GreatDB Software Co., Ltd
  7. Copyright (c) 2009-2023 Percona LLC and/or its affiliates
  8. Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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

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

  13. greatsql> show processlist;
  14. +---------+------+-----------------+------+---------+------+-------+------------------+---------+-----------+---------------+
  15. | Id      | User | Host            | db   | Command | Time | State | Info             | Time_ms | Rows_sent | Rows_examined |
  16. +---------+------+-----------------+------+---------+------+-------+------------------+---------+-----------+---------------+
  17. | 1990455 | yejr | 127.0.0.1:57108 | NULL | Query   |    0 | init  | show processlist |       0 |         0 |             0 |
  18. +---------+------+-----------------+------+---------+------+-------+------------------+---------+-----------+---------------+
  19. 1 row in set (0.00 sec)

  20. greatsql> select user();
  21. +----------------+
  22. | user()         |
  23. +----------------+
  24. | yejr@127.0.0.1 |
  25. +----------------+
  26. 1 row in set (0.00 sec)
复制代码
万里旅人 2024-5-22 21:45:30
15167759230 发表于 2024-5-17 20:33
grant Classmates to 'Rjh'@'localhost'这样授权,看看行不行。

还是不行,ID查不到
万里旅人 2024-5-22 21:51:41
15167759230 发表于 2024-5-17 20:48
grant all privileges on Students to Classmates;这个语句授权有问题吧,ON后面就是数据库名.表名吧 ...

结果是一样的,我简写了,刚才试了一下,还是不行,应该还是地址与授权问题
万里旅人

2

主题

0

博客

10

贡献

新手上路

Rank: 1

积分
17

合作电话:010-64087828

社区邮箱:greatsql@greatdb.com

社区公众号
社区小助手
QQ群
GMT+8, 2024-9-8 10:50 , Processed in 0.025711 second(s), 25 queries , Redis On.
快速回复 返回顶部 返回列表