一。權限
權限最大的用戶是:
sysdba和sysoper
1.創建用戶:
create user zhangsan identified by mima;
創建完的用戶沒有任何權限,包括登錄的權限都沒有。
2.用戶授權
grant create tablespace,connect to zhangsan;
3.一個開發者需要的權限:
創建會話:grant create session to 用戶名;
創建表:grant create table to 用戶名;
創建視圖:
創建序列:
創建過程:
4.dba給用戶修改密碼:
alter user scott identified by tiger;
5.對象權限:
對象權限 | 表 | 視圖 | 序列 | 存儲過程 |
---|---|---|---|---|
alter | √ | √ | ||
delete | √ | √ | ||
execute | √ | |||
index | √ | |||
insert | √ | √ | ||
references | √ | |||
select | √ | √ | √ | |
update | √ | √ |
6.授予對象權限
①授予在emp表上進行查詢的權限:
grant select
on emp
to sue,rich;
②爲用戶和角色授予dept表上的某些列的修改權限:
grant update(dname, loc)
on dept
to jack,john;
③with grant option:
被授權的用戶還能把權限給其他人。
grant insert, select
on dept
to tom
with grant option;
④to public :
允許系統中所有用戶訪問Alice的dept表:
grant select
on alice.dept
to public;
7.回收對象權限
revoke select, insert
on dept
from scott;
注意:
假設Scott把權限給了A,A把權限給了B,那麼Scott只能收回A的權限,而不能收回B的權限。
如果Scott收回了A的權限,相應的B的權限也不存在了。
8.驗證授權情況
數據字典表 | 描述 |
---|---|
role_sys_privs | 授予角色的系統權限 |
role_tab_privs | 授予角色的表權限 |
user_role_privs | 用戶能存取的角色 |
user_tab_privs_made | 在用戶對象上所授予的系統權限情況 |
user_tab_privs_recd | 授權給用戶的對象權限 |
user_col_privs_made | 在用戶對象的列上所授予的對象權限情況 |
user_col_privs_recd | 授予對象的某些列的對象權限情況 |
二。角色
Oracle用角色來簡化對權限的管理。
1.創建角色:
create role manage;
2.給角色授權:
grant create table,create view to manage;
3.授予開發者的角色:
grant connect, resource to 開發者;
其中,connect和resource是dba默認的角色。