Oracle 使用權限設定

來源:互聯網
上載者:User

一、許可權分類:
系統許可權:系統規定使用者使用資料庫的許可權。(系統許可權是對使用者而言)。

實體許可權:某種許可權使用者對其它使用者的表或視圖的存取許可權。(是針對錶或視圖而言的)。

二、系統許可權管理:
1、系統許可權分類:
DBA: 擁有全部特權,是系統最高許可權,只有DBA才可以建立資料庫結構。

RESOURCE:擁有Resource許可權的使用者只可以建立實體,不可以建立資料庫結構。

CONNECT:擁有Connect許可權的使用者只可以登入Oracle,不可以建立實體,不可以建立資料庫結構。

對於普通使用者:授予connect, resource許可權。
對於DBA系統管理使用者:授予connect,resource, dba許可權。

2、系統許可權授權命令:
[系統許可權只能由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則將使用者連同其建立的東西全部刪除

3、系統許可權傳遞:
增加WITH ADMIN OPTION選項,則得到的許可權可以傳遞。

SQL> grant connect, resorce to user50 with admin option;  //可以傳遞所獲許可權。

4、系統許可權回收:系統許可權只能由DBA使用者回收
命令:SQL> Revoke connect, resource from user50;

系統許可權無級聯,即A授予B許可權,B授予C許可權,如果A收回B的許可權,C的許可權不受影響;系統許可權可以跨使用者回收,即A可以直接收回C使用者的許可權。

三、實體許可權管理
1、實體許可權分類: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;  //傳遞的許可權將全部丟失。

四、同義字(Synonym):

1、建立私人同義字:
文法:SQL> create synonym 同義字名 for 代替項;

user01:
SQL> grant select, upate on product to user02;

user02:
SQL> Create synonym product for user01.product;

SQL> select * from product;  // 這裡的product即user01.product。

同義字資料字典:
SQL> select synonym_name, owner, table_name from all_synonyms;
SQL> select synonym_name, table_name from user_synonyms;

2、DBA可以建立公用同義字(Public Synonym):公用同義字全體使用者可以存取
文法:SQL> create public synonym 公用同義字名 for 代替項;

SCOTT:
SQL> grant select on payment to public;

SYSTEM:
SQL> create public synonym payment for scott.payment;

3. 刪除同義字:
User:SQL> drop synonym 私人同義字名;

DBA: SQL> drop public synonym 公用同義字名;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.