2016-02-29 39 views
1

我想用表格的條件來進行授予。 表中的用戶名將獲得授權許可。用條件在mysql中的格蘭特

mysql> select * from teacher; 
+------------+-----------------------+---------+----------------------------+ | 
teacher_id | teacher_name   | dept_id | subject    | 

+------------+-----------------------+---------+----------------------------+ 
|   1 | Daw Khine Yin Mon  |  1 | English    | 
|   2 | Daw Ei Ei Nway  |  1 | English    | 
|   3 | Daw Thiri Kyaw  |  1 | English    | 
|   4 | U Nay Lin Soe   |  1 | English    | 
|   5 | Daw Zin Mar Thwal  |  1 | English    | 

這是老師的桌子和我做他們的用戶通過......

Create user 'Daw Khine Yin Mo' identified by 'asd'; 
Create user 'Daw Ei Ei Nway' identified by 'asd'; 
Create user 'Daw Thiri Kyaw' identified by 'asd'; 
Create user 'U Nay Lin Soe' identified by 'asd'; 
Create user 'Daw Zin Mar Thw' identified by 'asd'; 

我承認他們作爲...

Grant select(teacher_id,rate_no) on rating to 'Daw Khine Yin Mo','Daw Ei Ei Nway'; 

我要讓這樣的條件...

Grant select(teacher_id,rate_no) on rating to 'Daw Khine Yin Mo' where teacher.teacher_name ='Daw Khine Yin Mon'; 

我該怎麼做?

+1

創建一個視圖,授予在視圖上的選擇。 – jarlh

回答

1

創建一個視圖,然後授予對該視圖的訪問權限。

CREATE VIEW 
    viewName 
AS 
    SELECT(teacher_id,rate_no) 
    FROM RATING 
    WHERE teacher.teacher_name ='Daw Khine Yin Mon' 

GRANT ALL ON viewName TO 'Daw Khine Yin Mo' 
+0

謝謝,這很有幫助。 我創建了每個老師作爲用戶。所以我應該爲每個用戶做每個視圖? –