Oracle用戶、權限、角色管理

Oracle 數據庫用戶管理
Oracle 權限設置
1、權限分類:
系統權限:系統規定用戶使用數據庫的權限。(系統權限是對用戶而言)。
實體權限:某種權限用戶對其它用戶的表或視圖的存取權限。(是針對表或視圖而言的)。
2、系統權限管理:
一、系統權限分類:
DBA: 擁有所有特權,是系統最高權限,只有DBA才能夠建立數據庫結構。
RESOURCE:擁有Resource權限的用戶只能夠建立實體,不能夠建立數據庫結構。
CONNECT:擁有Connect權限的用戶只能夠登陸Oracle,不能夠建立實體,不能夠建立數據庫結構。
對於普通用戶:授予connect, resource權限。
對於DBA管理用戶:授予connect,resource, dba權限。
二、系統權限受權命令:
[系統權限只能由DBA用戶授出:sys, system(最開始只能是這兩個用戶)]
受權命令:SQL> grant connect, resource, dba to 用戶名1 [,用戶名2]...;
[普通用戶經過受權能夠具備與system相同的用戶權限,但永遠不能達到與sys用戶相同的權限,system用戶的權限也能夠被回收。]
例:
SQL> connect system/manager
SQL> Create user user50 identified by user50;
SQL> grant connect, resource to user50;
查詢用戶擁有哪裏權限:
SQL> select * from dba_role_privs;
SQL> select * from dba_sys_privs;
SQL> select * from role_sys_privs;
刪除用戶:SQL> drop user 用戶名 cascade;  //加上cascade則將用戶連同其建立的東西所有刪除
三、系統權限傳遞:
增長WITH ADMIN OPTION選項,則獲得的權限能夠傳遞。
SQL> grant connect, resorce to user50 with admin option;  //能夠傳遞所獲權限。
四、系統權限回收:系統權限只能由DBA用戶回收
命令:SQL> Revoke connect, resource from user50;
系統權限無級聯,即A授予B權限,B授予C權限,若是A收回B的權限,C的權限不受影響;系統權限能夠跨用戶回收,即A能夠直接收回C用戶的權限。
3、實體權限管理
一、實體權限分類:select, update, insert, alter, index, delete, all  //all包括全部權限
execute  //執行存儲過程權限
user01:
SQL> grant select, update, insert on product to user02;
SQL> grant all on product to user02;
user02:
SQL> select * from user01.product;
// 此時user02查user_tables,不包括user01.product這個表,但若是查all_tables則能夠查到,由於他能夠訪問。

3. 將表的操做權限授予全體用戶:
SQL> grant all on product to public;  // public表示是全部的用戶,這裏的all權限不包括drop。
[實體權限數據字典]:
SQL> select owner, table_name from all_tables; // 用戶能夠查詢的表
SQL> select table_name from user_tables;  // 用戶建立的表
SQL> select grantor, table_schema, table_name, privilege from all_tab_privs; // 獲權能夠存取的表(被受權的)
SQL> select grantee, owner, table_name, privilege from user_tab_privs;   // 授出權限的表(授出的權限)
4. DBA用戶能夠操做全體用戶的任意基表(無需受權,包括刪除):
DBA用戶:
SQL> Create table stud02.product(
 id number(10),
 name varchar2(20));
SQL> drop table stud02.emp;
SQL> create table stud02.employee
 as
 select * from scott.emp;
 
5. 實體權限傳遞(with grant option):
user01:
SQL> grant select, update on product to user02 with grant option; // user02獲得權限,並能夠傳遞。
6. 實體權限回收:
user01:
SQL>Revoke select, update on product from user02;  //傳遞的權限將所有丟失。

1、建立用戶的Profile文件
SQL> create profile student limit  // student爲資源文件名
 FAILED_LOGIN_ATTEMPTS  3  //指定鎖定用戶的登陸失敗次數
 PASSWORD_LOCK_TIME 5  //指定用戶被鎖定天數
 PASSWORD_LIFE_TIME 30  //指定口令可用天數
 
2、建立用戶
SQL> Create User username
 Identified by password
 Default Tablespace tablespace
 Temporary Tablespace tablespace
 Profile profile
 Quota integer/unlimited on tablespace;
例:
SQL> Create user acc01
 identified by acc01   // 若是密碼是數字,請用雙引號括起來
 default tablespace account
 temporary tablespace temp
 profile default
 quota 50m on account;
SQL> grant connect, resource to acc01;
[*] 查詢用戶缺省表空間、臨時表空間
SQL> select username, default_tablespace, temporary_tablespace from dba_users;
[*] 查詢系統資源文件名:
SQL> select * from dba_profiles;
資源文件相似表,一旦建立就會保存在數據庫中。
SQL> select username, profile, default_tablespace, temporary_tablespace from dba_users;
SQL> create profile common limit
 failed_login_attempts 5
 idle_time 5;
 
SQL> Alter user acc01 profile common;
3、修改用戶:
SQL> Alter User 用戶名
 Identified 口令
 Default Tablespace tablespace
 Temporary Tablespace tablespace
 Profile profile
 Quota integer/unlimited on tablespace;
 
一、修改口令字:
SQL>Alter user acc01 identified by "12345";
二、修改用戶缺省表空間:
SQL> Alter user acc01 default tablespace users;
三、修改用戶臨時表空間
SQL> Alter user acc01 temporary tablespace temp_data;
四、強制用戶修改口令字:
SQL> Alter user acc01 password expire;
五、將用戶加鎖
SQL> Alter user acc01 account lock;  // 加鎖
SQL> Alter user acc01 account unlock;  // 解鎖
4、刪除用戶
SQL>drop user 用戶名;  //用戶沒有建任何實體
SQL> drop user 用戶名 CASCADE;  // 將用戶及其所建實體所有刪除
*1. 當前正鏈接的用戶不得刪除。

5、監視用戶:
一、查詢用戶會話信息:
SQL> select username, sid, serial#, machine from v$session;
二、刪除用戶會話信息:
SQL> Alter system kill session 'sid, serial#';
三、查詢用戶SQL語句:
SQL> select user_name, sql_text from v$open_cursor;
SQL> ALTER SESSION SET
 NLS_LANGUAGE= 'SIMPLIFIED CHINESE'
 NLS_TERRITORY= 'CHINA'
 NLS_CURRENCY= 'RMB'
 NLS_ISO_CURRENCY= 'CHINA'
 NLS_NUMERIC_CHARACTERS= '.,'
 NLS_CALENDAR= 'GREGORIAN'
 NLS_DATE_FORMAT= 'yyyy-mm-dd dy'
 NLS_DATE_LANGUAGE= 'SIMPLIFIED CHINESE' 
 NLS_SORT= 'BINARY'
 TIME_ZONE= '+08:00'
 NLS_DUAL_CURRENCY = 'RMB'
 NLS_TIME_FORMAT = 'HH.MI.SSXFF AM'
 NLS_TIMESTAMP_FORMAT = 'DD-MON-RR HH.MI.SSXFF AM'
 NLS_TIME_TZ_FORMAT = 'HH.MI.SSXFF AM TZH:TZM'
 NLS_TIMESTAMP_TZ_FORMAT = 'DD-MON-RR HH.MI.SSXFF AM TZH:TZM'

 
1、Oracle 權限管理
SQL> grant connect, resource, dba to acc01;
SQL> revoke connect, resource from acc01;
2、Oracle 角色管理
SQL> Create Role <role_name>
 Identified by password/ Not Identified;
 
SQL> Alter Role <role_name> ...
SQL> Grant <privs> to <role_name>;
SQL> Grant <role_name> to <user_name>
SQL> Set Role <role_name>  All Except <role_name2> / None 
相關文章
相關標籤/搜索