Oracle許可權和角色管理概述

來源:互聯網
上載者:User

Oracle的許可權有兩種:

system privileges:使用者所做的操作會對資料字典造成影響;

object privileges:使用者所做的操作會對資料造成影響;

 

System Privilege:

大概有200多個系統許可權,常用的系統許可權包括:

  • CREATE SESSION
  • RESTRICTED SESSION:當資料庫處於restricted狀態的時候,這些使用者可以進入;
  • ALTER DATABASE
  • ALTER SYSTEM
  • CREATE TABLESPACE
  • CREATE TABLE
  • GRANT ANY OBJECT PRIVILEGE
  • CREATE ANY TABLE
  • DROP ANY TABLE
  • INSERT ANY TABLE, UPDATE ANY TABLE, DELETE ANY TABLE
  • SELECT ANY TABLE

GRANTprivilege1,privilege2 TO username;

 

grantcreate table to scott with admin option;

connectscott/tiger;

grantcreate table to sj;

 

使用者scott只能在自己的schema中建立表

使用者sj也只能在自己的schema中建立表

如果將scott的該許可權收穫,sj的許可權將依舊存在;

 

--查看使用者所擁有的許可權,並且看其是否可以繼續授權

select * fromdba_sys_privs where grantee='SJ';

 

授予any table許可權的,任然不能操作SYS資料表空間中的表;

Object Privileges

可以將select,update,delete,insert,alter,execute等DML操作許可權賦給使用者,可以針對錶,也可以針對錶中的某些列,例:

grantselect  on scott.emp to sj;

grant update (order_status) on scott.orders to sj;--在列這個層級分配會造出嚴重的系統負擔;

grant allon scott.regions to sj;

Object Privileges 許可權可以級聯收回

revoke select  on scott.empfrom sj;-----------通過sj再賦予其他使用者的許可權在此語句執行後都將收回;

建立和管理角色

--查看使用者所擁有的角色,並查看是否可以繼續授權

select * fromdba_role_privs where grantee='SJ';

 

A role isbundle of system and/or object privileges that can be granted and revoked as aunit, and having been granted  can betemporarily activated or deactivated with in a session;

CREATE ROLE rolename;

角色的名字不能和現有使用者的使用者名稱重複,也不能和現有的角色名稱重複;

 

createrole hr_junior;

grantcreate session to hr_junior;

grantselect on hr.regions to hr_junior

 

createrole hr_senior;

granthr_junior to hr_senior with admin option;

grantupdate on hr.regions to hr_senior;

 

createrole hr_manager;

granthr_senior to hr_manager with admin option;

grant allon hr.regions to hr_manager;

 

和system privileges許可權的收回方式一樣,role的收回也是不能級聯進行的;

 

預先定義好的角色:

  • CONNECT:為了向後相容,現在改為CREATE SESSION,可以建立表
  • RESOURCE:為了向後相容,可以建立表或預存程序;並且有UNLIMITED TABLESACPE許可權;
  • DBA:幾乎具備所有的許可權,但是不能啟動和關閉資料庫;
  • SELECT_CATALOG_ROLE:資料庫初級管理員最好有這個,它能擁有許多object privileges的許可權,但是沒有system privileges的許可權,也沒有使用者資料的許可權,不能看到使用者資料;
  • SCHEDULER_ADMIN:具有管理批量計劃指令碼的許可權

 

there isalso a predefined role PUBLIC, which is always granted to every database useraccount;

例:grant select on hr.regions topublic;------通過執行這個語句,系統中的所有使用者都可以獲得對這個表的select許可權;

--將一個使用者的預設角色失效

ALTER UESR sj DEFAULT ROLE NONE;--當sj使用者登入的時候,它沒有任何可用的角色,甚至不能登入;

grant connect to sj --將登入角色賦給sj

alter user sj default role connect;---將登入角色作為sj的預設角色

SET ROLE rolename;

CTRATEROLE rolename IDENTIFIED USING procedure_name;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.