標籤:plain 訪問 source 比較 nts ide system exec toe
oracle資料庫的許可權系統分為系統許可權與對象許可權。系統許可權( database system privilege )可以讓使用者執行特定的命令集。例如,create table許可權允許使用者建立表,grant any privilege 許可權允許使用者授予任何系統許可權。對象許可權( database object privilege )可以讓使用者能夠對各個對象進行某些操作。例如delete許可權允許使用者刪除表或視圖的行,select許可權允許使用者通過select從表、視圖、序列(sequences)或快照(snapshots)中查詢資訊。
每個oracle使用者都有一個名字和口令,並擁有一些由其建立的表、視圖和其他資源。oracle角色(role)就是一組許可權(privilege)(或者是每個使用者根據其狀態和條件所需的訪問類型)。使用者可以給角色授予或賦予指定的許可權,然後將角色賦給相應的使用者。一個使用者也可以直接給其他使用者授權。
一、建立使用者
oracle內部有兩個建好的使用者:system和sys。使用者可直接登入到system使用者以建立其他使用者,因為system具有建立別 的使用者的 許可權。 在安裝oracle時,使用者或系統管理員首先可以為自己建立一個使用者。
文法[建立使用者]: create user 使用者名稱 identified by 口令[即密碼];
例子: create user test identified by test;
文法[更改使用者]: alter user 使用者名稱 identified by 口令[改變的口令];
例子: alter user test identified by 123456;
二、刪除使用者
文法:drop user 使用者名稱;
例子:drop user test;
若使用者擁有對象,則不能直接刪除,否則將返回一個錯誤值。指定關鍵字cascade,可刪除使用者所有的對象,然後再刪除使用者。
文法:drop user 使用者名稱 cascade;
例子:drop user test cascade;
三、授權角色
oracle為相容以前版本,提供三種標準角色(role):connect/resource和dba.
(1)講解三種標準角色:
1》. connect role(串連角色)
--臨時使用者,特指不需要建表的使用者,通常只賦予他們connect role.
--connect是使用oracle簡單許可權,這種許可權只對其他使用者的表有存取權限,包括select/insert/update和delete等。
--擁有connect role 的使用者還能夠建立表、視圖、序列(sequence)、簇(cluster)、同義字(synonym)、回話(session)和其他 資料的鏈(link)
2》. resource role(資源角色)
--更可靠和正式的資料庫使用者可以授予resource role。
--resource提供給使用者另外的許可權以建立他們自己的表、序列、過程(procedure)、觸發器(trigger)、索引(index)和簇(cluster)。
3》. dba role(資料庫管理員角色)
--dba role擁有所有的系統許可權
--包括無限制的空間限額和給其他使用者授予各種許可權的能力。system由dba使用者擁有
(2)授權命令
文法: grant connect, resource to 使用者名稱;
例子: grant connect, resource to test;
(3)撤銷許可權
文法: revoke connect, resource from 使用者名稱;
列子: revoke connect, resource from test;
四、建立/授權/刪除角色
除了前面講到的三種系統角色----connect、resource和dba,使用者還可以在oracle建立自己的role。使用者建立的role可以由表或系統許可權或兩者的組合構成。為了建立role,使用者必須具有create role系統許可權。
1》建立角色
文法: create role 角色名稱;
例子: create role testRole;
2》授權角色
文法: grant select on class to 角色名稱;
列子: grant select on class to testRole;
註:現在,擁有testRole角色的所有使用者都具有對class表的select查詢許可權
3》刪除角色
文法: drop role 角色名稱;
例子: drop role testRole;
註:與testRole角色相關的許可權將從資料庫全部刪除
許可權:
create session
create table
unlimited tablespace
connect
resource
dba
例:
#sqlplus /nolog
SQL> conn / as sysdba;
SQL>create user username identified by password
SQL> grant dba to username;
SQL> conn username/password
SQL> select * from user_sys_privs;
我們將從建立Oracle使用者權限表開始談起,然後講解登陸等一般性動作,使大家對Oracle使用者權限表有個深入的瞭解。
一、建立
sys;//系統管理員,擁有最高許可權
system;//本地管理員,次高許可權
scott;//普通使用者,密碼預設為tiger,預設未解鎖
二、登陸
sqlplus / as sysdba;//登陸sys帳戶
sqlplus sys as sysdba;//同上
sqlplus scott/tiger;//登陸普通使用者scott
三、系統管理使用者
create user zhangsan;//在系統管理員帳戶下,建立使用者zhangsan
alert user scott identified by tiger;//修改密碼
四,授予許可權
1、預設的普通使用者scott預設未解鎖,不能進行那個使用,建立的使用者也沒有任何許可權,必須授予許可權
grant create session to zhangsan;//授予zhangsan使用者建立session的許可權,即登陸許可權
grant unlimited tablespace to zhangsan;//授予zhangsan使用者使用資料表空間的許可權
grant create table to zhangsan;//授予建立表的許可權
grante drop table to zhangsan;//授予刪除表的許可權
grant insert table to zhangsan;//插入表的許可權
grant update table to zhangsan;//修改表的許可權
grant all to public;//這條比較重要,授予所有許可權(all)給所有使用者(public)
2、oralce對許可權管理比較嚴謹,普通使用者之間也是預設不能互相訪問的,需要互相授權
grant select on tablename to zhangsan;//授予zhangsan使用者查看指定表的許可權
grant drop on tablename to zhangsan;//授予刪除表的許可權
grant insert on tablename to zhangsan;//授予插入的許可權
grant update on tablename to zhangsan;//授予修改表的許可權
grant insert(id) on tablename to zhangsan;
grant update(id) on tablename to zhangsan;//授予對指定表特定欄位的插入和修改許可權,注意,只能是insert和update
grant alert all table to zhangsan;//授予zhangsan使用者alert任意表的許可權
五、撤銷許可權
基本文法同grant,關鍵字為revoke
六、查看許可權
select * from user_sys_privs;//查看目前使用者所有許可權
select * from user_tab_privs;//查看所用使用者對錶的許可權
七、動作表的使用者的表
select * from zhangsan.tablename
八、許可權傳遞
即使用者A將許可權授予B,B可以將操作的許可權再授予C,命令如下:
grant alert table on tablename to zhangsan with admin option;//關鍵字 with admin option
grant alert table on tablename to zhangsan with grant option;//關鍵字 with grant option效果和admin類似
九、角色
角色即許可權的集合,可以把一個角色授予給使用者
create role myrole;//建立角色
grant create session to myrole;//將建立session的許可權授予myrole
grant myrole to zhangsan;//授予zhangsan使用者myrole的角色
drop role myrole;刪除角色
Oracle建立資料表空間和使用者
[sql] view plain copy
- 建立資料表空間和使用者的步驟:
- 使用者
- 建立:create user 使用者名稱 identified by "密碼";
- 授權:grant create session to 使用者名稱;
- grant create table to 使用者名稱;
- grant create tablespace to 使用者名稱;
- grant create view to 使用者名稱;
[sql] view plain copy
- 資料表空間
- 建立資料表空間(一般建N個存資料的資料表空間和一個索引空間):
- create tablespace 資料表空間名
- datafile ‘ 路徑(要先建好路徑)\***.dbf ‘ size *M
- tempfile ‘ 路徑\***.dbf ‘ size *M
- autoextend on --自動成長
- --還有一些定義大小的命令,看需要
- default storage(
- initial 100K,
- next 100k,
- );
[sql] view plain copy
- 例子:建立資料表空間
- create tablespace DEMOSPACE
- datafile ‘E:/oracle_tablespaces/DEMOSPACE_TBSPACE.dbf‘
- size 1500M
- autoextend on next 5M maxsize 3000M;
- 刪除資料表空間
- drop tablespace DEMOSPACE including contents and datafiles
[sql] view plain copy
- 使用者權限
- 授予使用者使用資料表空間的許可權:
- alter user 使用者名稱 quota unlimited on 資料表空間;
- 或 alter user 使用者名稱 quota *M on 資料表空間;
完整例子:
[sql] view plain copy
- --資料表空間
- CREATE TABLESPACE sdt
- DATAFILE ‘F:\tablespace\demo‘ size 800M
- EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
- --索引資料表空間
- CREATE TABLESPACE sdt_Index
- DATAFILE ‘F:\tablespace\demo‘ size 512M
- EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
-
- --2.建使用者
- create user demo identified by demo
- default tablespace std;
-
- --3.賦權
- grant connect,resource to demo;
- grant create any sequence to demo;
- grant create any table to demo;
- grant delete any table to demo;
- grant insert any table to demo;
- grant select any table to demo;
- grant unlimited tablespace to demo;
- grant execute any procedure to demo;
- grant update any table to demo;
- grant create any view to demo;
[sql] view plain copy
- --匯入匯出命令
- ip匯出方式: exp demo/[email protected]:1521/orcl file=f:/f.dmp full=y
- exp demo/[email protected] file=f:/f.dmp full=y
- imp demo/[email protected] file=f:/f.dmp full=y ignore=y
Oracle建立使用者、角色、授權、建資料表空間