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
username
1 [,
username
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 username 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;
?
說明:
1 )假設(shè)使用 WITH ADMIN OPTION 為某個(gè)用戶授予系統(tǒng)權(quán)限,那么對于被這個(gè)用戶授予同樣權(quán)限的全部用戶來說,取消該用戶的系統(tǒng)權(quán)限并不會級聯(lián)取消這些用戶的同樣權(quán)限。
2 )系統(tǒng)權(quán)限無級聯(lián),即 A 授予 B 權(quán)限, B 授予 C 權(quán)限,假設(shè) 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? //
運(yùn)行存儲過程權(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è)表,但假設(shè)查 all_tables 則能夠查到,由于他能夠訪問。
2.
將表的操作權(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)限
)
?
3. 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;
?
4.
實(shí)體權(quán)限傳遞
(with grant option)
:
user01:
SQL> grant select, update on product to user02 with grant option; // user02 得到權(quán)限,并能夠傳遞。
?
5.
實(shí)體權(quán)限回收:
user01:
SQL>Revoke select, update on product from user02;? //
傳遞的權(quán)限將所有丟失。
?
說明
1 )假設(shè)取消某個(gè)用戶的對象權(quán)限,那么對于這個(gè)用戶使用 WITH GRANT OPTION 授予權(quán)限的用戶來說,相同還會取消這些用戶的相同權(quán)限,也就是說取消授權(quán)時(shí)級聯(lián)的。
?
?
Oracle
用戶管理
一、創(chuàng)建用戶的
Profile
文件
SQL> create profile student limit? // student
為資源文件名稱
?FAILED_LOGIN_ATTEMPTS? 3? //
指定鎖定用戶的登錄失敗次數(shù)
?PASSWORD_LOCK_TIME 5? //
指定用戶被鎖定天數(shù)
?PASSWORD_LIFE_TIME 30? //
指定口令可用天數(shù)
?
二、創(chuàng)建用戶
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?? //
假設(shè)password是數(shù)字,請用雙引號括起來
?default tablespace account
?temporary tablespace temp
?profile default
?quota 50m on account;
SQL> grant connect, resource to acc01;
[*]
查詢用戶缺省表空間、暫時(shí)表空間
SQL> select username, default_tablespace, temporary_tablespace from dba_users;
[*]
查詢系統(tǒng)資源文件名稱:
SQL> select * from dba_profiles;
資源文件相似表,一旦創(chuàng)建就會保存在數(shù)據(jù)庫中。
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;
?
三、改動(dòng)用戶:
SQL> Alter User
username
?Identified
口令
?Default Tablespace tablespace
?Temporary Tablespace tablespace
?Profile profile
?Quota integer/unlimited on tablespace;
?
1
、改動(dòng)口令字:
SQL>Alter user acc01 identified by "12345";
2
、改動(dòng)用戶缺省表空間:
SQL> Alter user acc01 default tablespace users;
3
、改動(dòng)用戶暫時(shí)表空間
SQL> Alter user acc01 temporary tablespace temp_data;
4
、強(qiáng)制用戶改動(dòng)口令字:
SQL> Alter user acc01 password expire;
5
、將用戶加鎖
SQL> Alter user acc01 account lock;? //
加鎖
SQL> Alter user acc01 account unlock;? //
解鎖
?
四、刪除用戶
SQL>drop user
username
;? //
用戶沒有建不論什么實(shí)體
SQL> drop user
username
CASCADE;? //
將用戶及其所建實(shí)體所有刪除
*1. 當(dāng)前正連接的用戶不得刪除。
五、監(jiān)視用戶:
1
、查詢用戶會話信息:
SQL> select username, sid, serial#, machine from v$session;
2
、刪除用戶會話信息:
SQL> Alter system kill session 'sid, serial#';
3
、查詢用戶
SQL
語句:
SQL> select user_name, sql_text from v$open_cursor;
?
?
Oracle 角色管理
一、何為角色
角色。角色是一組權(quán)限的集合,將角色賦給一個(gè)用戶,這個(gè)用戶就擁有了這個(gè)角色中的全部權(quán)限。
二、系統(tǒng)提前定義角色
提前定義角色是在數(shù)據(jù)庫安裝后,系統(tǒng)自己主動(dòng)創(chuàng)建的一些經(jīng)常使用的角色。下介簡單的介紹一下這些預(yù)定角色。角色所包括的權(quán)限能夠用下面語句查詢:
sql>select * from role_sys_privs where role='
角色名
';
1
.
CONNECT, RESOURCE, DBA
這些提前定義角色主要是為了向后兼容。其主要是用于數(shù)據(jù)庫管理。
oracle
建議用戶自己設(shè)計(jì)數(shù)據(jù)庫管理和安全的權(quán)限規(guī)劃,而不要簡單的使用這些預(yù)定角色。將來的版本號中這些角色可能不會作為提前定義角色。
?
2
.
DELETE_CATALOG_ROLE
,
EXECUTE_CATALOG_ROLE
,
SELECT_CATALOG_ROLE
這些角色主要用于訪問數(shù)據(jù)字典視圖和包。
?
3
.
EXP_FULL_DATABASE
,
IMP_FULL_DATABASE
這兩個(gè)角色用于數(shù)據(jù)導(dǎo)入導(dǎo)出工具的使用。
?
4
.
AQ_USER_ROLE
,
AQ_ADMINISTRATOR_ROLE
AQ:Advanced Query
。這兩個(gè)角色用于
oracle
高級查詢功能。
?
5
.
SNMPAGENT
用于
oracle enterprise manager
和
Intelligent Agent
?
6
.
RECOVERY_CATALOG_OWNER
用于創(chuàng)建擁有恢復(fù)庫的用戶。關(guān)于恢復(fù)庫的信息,參考
oracle
文檔《
Oracle9i User-Managed Backup and Recovery Guide
》
?
7
.
HS_ADMIN_ROLE
A DBA using Oracle's heterogeneous services feature needs this role to access appropriate tables in the data dictionary.
?
三、管理角色
1.
建一個(gè)角色
sql>create role role1;
2.
授權(quán)給角色
sql>grant create any table,create procedure to role1;
3.
授予角色給用戶
sql>grant role1 to user1;
4.
查看角色所包括的權(quán)限
sql>select * from role_sys_privs;
5.
創(chuàng)建帶有口令以角色
(
在生效帶有口令的角色時(shí)必須提供口令
)
sql>create role role1 identified by password1;
6.
改動(dòng)角色:是否須要口令
sql>alter role role1 not identified;
sql>alter role role1 identified by password1;
7.
設(shè)置當(dāng)前用戶要生效的角色
(
注:角色的生效是一個(gè)什么概念呢?如果用戶
a
有
b1,b2,b3
三個(gè)角色,那么如果
b1
未生效,則
b1
所包括的權(quán)限對于
a
來講是不擁有的,僅僅有角色生效了,角色內(nèi)的權(quán)限才作用于用戶,最大可生效角色數(shù)由參數(shù)
MAX_ENABLED_ROLES
設(shè)定;在用戶登錄后,
oracle
將全部直接賦給用戶的權(quán)限和用戶默認(rèn)角色中的權(quán)限賦給用戶。)
sql>set role role1;//
使
role1
生效
sql>set role role,role2;//
使
role1,role2
生效
sql>set role role1 identified by password1;//
使用帶有口令的
role1
生效
sql>set role all;//
使用該用戶的全部角色生效
sql>set role none;//
設(shè)置全部角色失效
sql>set role all except role1;//
除
role1
外的該用戶的全部其他角色生效。
sql>select * from SESSION_ROLES;//
查看當(dāng)前用戶的生效的角色。
8.
改動(dòng)指定用戶,設(shè)置其默認(rèn)角色
sql>alter user user1 default role role1;
sql>alter user user1 default role all except role1;
詳見
oracle
參考文檔
9.
刪除角色
sql>drop role role1;
角色刪除后,原來擁用該角色的用戶就不再擁有該角色了,對應(yīng)的權(quán)限也就沒有了。
?
說明 :
1) 無法使用 WITH GRANT OPTION 為角色授予對象權(quán)限
2) 能夠使用 WITH ADMIN OPTION 為角色授予系統(tǒng)權(quán)限 , 取消時(shí)不是級聯(lián)
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
