How to Enable Read-Only Permissions for Views

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 如何开通视图只读权限

| username: 孤君888

[TiDB Usage Environment] Production Environment / Testing / Poc
[TiDB Version]
[Reproduction Path] What operations were performed when the issue occurred
[Encountered Issue: Issue Phenomenon and Impact]

As the title suggests, how can I create a new user and grant them read-only permissions on a view?

[Resource Configuration]
[Attachments: Screenshots/Logs/Monitoring]

| username: 我是咖啡哥 | Original post link

grant show view on *.* to user

| username: 孤君888 | Original post link

It won’t work. If you set this permission separately, you will get an error when you initiate SELECT * FROM VIEW.

| username: 孤君888 | Original post link

Permissions are as follows

mysql> show grants for v_ro@'%' ;
+--------------------------------------+
| Grants for v_ro@%                    |
+--------------------------------------+
| GRANT SHOW VIEW ON *.* TO 'v_ro'@'%' |
+--------------------------------------+
1 row in set (0.00 sec)

Error is as follows

mysql> show grants;
+--------------------------------------+
| Grants for User                      |
+--------------------------------------+
| GRANT SHOW VIEW ON *.* TO 'v_ro'@'%' |
+--------------------------------------+
1 row in set (0.00 sec)

mysql> select * from view_XXX ;
ERROR 1142 (42000): SELECT command denied to user 'v_ro'@'%' for table 'view_XXX'
mysql>
| username: 我是咖啡哥 | Original post link

The tables involved in the view must have query permissions.

| username: 孤君888 | Original post link

I have many views, and there are also many tables involved. Do I still need to add select query permissions one by one?

| username: 胡杨树旁 | Original post link

You should grant permissions on the tables within the view.

| username: 我是咖啡哥 | Original post link

If strict control is not necessary, just grant select permissions to all tables. If you need to strictly control access to each table, you will have to identify and manage them one by one.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.