当前位置:网站首页>MySQL grants the user the operation permission of the specified content

MySQL grants the user the operation permission of the specified content

2022-07-06 15:57:00 Flame car

Grant users a library 、 The permissions of a table or a column can be easily found (GRANT), But there is a problem: how to grant the user the operation permission of the specified content ??

A problem of database experiment :
Suppose a user is CS Department managers , The authority that needs to be given to him only includes adding, deleting, checking and modifying the information of the computer department teacher , How to achieve ?

At first, I thought it was the same as specifying a column , Nothing more than specifying a certain line . Then Baidu spent a long time and found that it didn't say what to do at all ? Then it's time to go to bed , Suddenly thought of whether to re create a table and specify the rows of the things on that table ( Department of Computer Science ) Let it go ?
Come here , I suddenly remembered that one of the videos given by the teacher was view operation ( Why didn't I see it ???), I wonder if I should map the table to the view first , Then give the permission of the view to the user ? Then I checked again , You can modify the original table by modifying the view , That is to say, it really does .

summary : The user is not directly authorized to operate the specified content GRANT, You need to create a view through conditions and then grant users the operation permission of the view to achieve this effect .

Specific operation :

CREATE VIEW cs_instructor AS
SELECT *
FROM instructor
WHERE dept_name = 'Comp. Sci.'

Create a view , Inside is the information of the computer department teacher .

GRAND SELECT ON cs_instructor TO 'name'@'localhost';

In this way, the permission is granted to the user ,TO The following single quotation mark can be added or not .

Then you may have to modify the permissions of the view , hold Definer Change it to Invoker, But I don't know why I use it instead Definer To open ……

原网站

版权声明
本文为[Flame car]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060919551744.html