Oracle 數(shù)據(jù)庫用戶管理 Oracle 權(quán)限設(shè)置
一、權(quán)限分類:
系統(tǒng)權(quán)限:系統(tǒng)規(guī)定用戶使用數(shù)據(jù)庫的權(quán)限。(系統(tǒng)權(quán)限是對用戶而言)。 實(shí)體權(quán)限:某種權(quán)限用戶對其它用戶的表或視圖的存取權(quán)限。(是針對表或視圖而言的)。
二、系統(tǒng)權(quán)限管理:
1、系統(tǒng)權(quán)限分類:
DBA: 擁有全部特權(quán),是系統(tǒng)最高權(quán)限,只有DBA才可以創(chuàng)建數(shù)據(jù)庫結(jié)構(gòu)。 RESOURCE:擁有Resource權(quán)限的用戶只可以創(chuàng)建實(shí)體,不可以創(chuàng)建數(shù)據(jù)庫結(jié)構(gòu)。 CONNECT:擁有Connect權(quán)限的用戶只可以登錄Oracle,不可以創(chuàng)建實(shí)體,不可以創(chuàng)建數(shù)據(jù)庫結(jié)構(gòu)。 對于普通用戶:授予connect, resource權(quán)限。
對于DBA管理用戶:授予connect,resource, dba權(quán)限。
2、系統(tǒng)權(quán)限授權(quán)命令:
[系統(tǒng)權(quán)限只能由DBA用戶授出:sys, system(最開始只能是這兩個(gè)用戶)]
授權(quán)命令:SQL> grant connect, resource, dba to 用戶名1 [,用戶名2]...; [普通用戶通過授權(quán)可以具有與system相同的用戶權(quán)限,但永遠(yuǎn)不能達(dá)到與sys用戶相同的權(quán)限,system用戶的權(quán)限也可以被回收。] 例:
SQL> connect system/manager
SQL> Create user user50 identified by user50;
SQL> grant connect, resource to user50; 查詢用戶擁有哪里權(quán)限:
SQL> select * from dba_role_privs;
SQL> select * from dba_sys_privs;
SQL> select * from role_sys_privs; 刪除用戶:SQL> drop user 用戶名 cascade; //加上cascade則將用戶連同其創(chuàng)建的東西全部刪除
3、系統(tǒng)權(quán)限傳遞:
增加WITH ADMIN OPTION選項(xiàng),則得到的權(quán)限可以傳遞。 SQL> grant connect, resorce to user50 with admin option; //可以傳遞所獲權(quán)限。
4、系統(tǒng)權(quán)限回收:系統(tǒng)權(quán)限只能由DBA用戶回收
命令:SQL> Revoke connect, resource from user50; 系統(tǒng)權(quán)限無級聯(lián),即A授予B權(quán)限,B授予C權(quán)限,如果A收回B的權(quán)限,C的權(quán)限不受影響;系統(tǒng)權(quán)限可以跨用戶回收,即A可以直接收回C用戶的權(quán)限。 三、實(shí)體權(quán)限管理
1、實(shí)體權(quán)限分類:select, update, insert, alter, index, delete, all //all包括所有權(quán)限
execute //執(zhí)行存儲(chǔ)過程權(quán)限 user01:
SQL> grant select, update, insert on product to user02;
SQL> grant all on product to user02; user02:
SQL> select * from user01.product; // 此時(shí)user02查user_tables,不包括user01.product這個(gè)表,但如果查all_tables則可以查到,因?yàn)樗梢栽L問。
3. 將表的操作權(quán)限授予全體用戶:
SQL> grant all on product to public; // public表示是所有的用戶,這里的all權(quán)限不包括drop。 [實(shí)體權(quán)限數(shù)據(jù)字典]:
SQL> select owner, table_name from all_tables; // 用戶可以查詢的表
SQL> select table_name from user_tables; // 用戶創(chuàng)建的表
SQL> select grantor, table_schema, table_name, privilege from all_tab_privs; // 獲權(quán)可以存取的表(被授權(quán)的)
SQL> select grantee, owner, table_name, privilege from user_tab_privs; // 授出權(quán)限的表(授出的權(quán)限)
4. DBA用戶可以操作全體用戶的任意基表(無需授權(quán),包括刪除):
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. 實(shí)體權(quán)限傳遞(with grant option):
user01: SQL> grant select, update on product to user02 with grant option; // user02得到權(quán)限,并可以傳遞。
新聞熱點(diǎn)
疑難解答
圖片精選