查看登陸的用戶:
以下都可以:
show user;
select sys_context('userenv','session_user') from dual; -
select user from dual;
查看所有登錄的用戶必須為DBA 用戶:
select username from v$session;
sys、system等DBA 用戶查看 其他用戶(test)中的對(duì)象(表):
SQL> select * from test.student;
創(chuàng)建一個(gè)普通用戶都把該用戶用起來的流程:
1、創(chuàng)建用戶
SQL>create user test indentified by test;
這樣就創(chuàng)建了一個(gè)用戶名密碼都為test的用戶
但這個(gè)時(shí)候test還是不能登陸成功的,我們需要賦予相應(yīng)的權(quán)限
2、賦予create session的權(quán)限
SQL>grant create session to test;
這樣test用戶就能成功登陸進(jìn)去
但是此時(shí)用戶還是不能創(chuàng)建表 我們需要賦予用戶創(chuàng)建表的權(quán)限:
SQL>grant create table to test;
但是用戶此時(shí)還不能創(chuàng)建表 因?yàn)樾枰惺褂帽砜臻g的權(quán)限(相當(dāng)于 用戶有了進(jìn)房間的鑰匙 但是沒有進(jìn)大門的鑰匙。。。)
所以也應(yīng)該賦予相應(yīng)的權(quán)限
SQL>grant unlimited tablespace to test;
這個(gè)時(shí)候用戶就擁有了創(chuàng)建表的權(quán)限 由于表是用戶test的 相應(yīng)的他就擁有了對(duì)創(chuàng)建的表的增刪查改的權(quán)限了
3、查看用戶擁有什么權(quán)限可以通過查詢一個(gè)系統(tǒng)的視圖(數(shù)字字典)
SQL>select * from user_sys_privs;
這樣就可以知道當(dāng)前用戶的權(quán)限
4、撤銷權(quán)限
SQL> revoke create table from test;
-----------------------------
一些常用視圖的區(qū)分
dba_tables dba_all_tables user_tables user_all_tables all_tables all_all_tables
當(dāng)前用戶所屬的所有表(注意大寫)
SQL> select tablespace_name,table_name from user_all_tables where table_name='STUDENT';
SQL> select table_name,tablespace_name from user_tables where table_name='STUDENT';
TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
STUDENT USERS
sys 要查看dba_all_tables,ALL_ALL_TABLES才能查看到 test 用戶的表。
SQL> select owner,table_name,tablespace_name from dba_all_tables where owner='TEST';
SQL> select owner,table_name,tablespace_name from all_all_tables where owner='TEST';
SQL> select owner,table_name,tablespace_name from dba_tables where owner='TEST';
SQL> select owner,table_name,tablespace_name from ALL_tables where owner='TEST';
OWNER TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------ ------------------------------
TEST STUDENT USERS
1.DBA_ALL_TABLES describes all object tables and relational tables in the database. Its columns are the same as those in ALL_ALL_TABLES.
2.ALL_ALL_TABLES describes the object tables and relational tables accessible to the current user.
3.USER_ALL_TABLES describes the object tables and relational tables owned by the current user. Its columns (except for OWNER) are the same as those in
ALL_ALL_TABLES.
----------------------------------------------------------------------
情景一:
用戶test 用戶test1
test1的用戶創(chuàng)建了個(gè)表mytab 并且插入了一些數(shù)據(jù)
那么 test用戶是否可以訪問到test1的mytab怎么訪問?
答:不可以,必須先授權(quán)
test1必須授權(quán)給test :grant select on mytab to test;
那么這個(gè)時(shí)候test可以通過 select * from test1.mytab;來訪問mytab中的數(shù)據(jù)
如果想把某個(gè)表(對(duì)象)的所有權(quán)限都賦予給test那么可以:
grant all on mytab to test;
撤銷所有權(quán)限
revoke all on mytab to test;
總結(jié)
對(duì)于系統(tǒng)權(quán)限由sys來做
對(duì)于對(duì)象權(quán)限由 誰擁有誰授權(quán)
系統(tǒng)權(quán)限
grant create session to test;
grant create table to test;
grant unlimited tablespace to test;
revoke create session from test;
revoke create table from test;
revoke unlimited tablespase from test;
grant create session to public; //表示把創(chuàng)建表的權(quán)限賦予所有人
select * from user_sys_privs; //返回當(dāng)前用戶的所有系統(tǒng)權(quán)限
對(duì)象權(quán)限
grant select on mytab to test;
grant all on mytab to test;
revoke select on mytab from test;
revoke all on mytab from test;
select * from user_tab_privs; //返回當(dāng)前用戶所有的對(duì)象權(quán)限
對(duì)象權(quán)限可以控制到列
grant update(name) on mytab to test;
grant insert(id) on mytab to test;
select * from user_col_privs;
注意、:查詢和刪除不能控制到列
需要有commit的 insert update insert
權(quán)限的傳遞
系統(tǒng)權(quán)限的傳遞:
grant alter table to A with admin option;
那么A可以通過把該權(quán)限傳遞給B,如果想B也可以傳遞下去那么可以也帶上with admin option
grant alter table to B;
對(duì)象權(quán)限的傳遞:
grant select on mytab to A with grant option;
那么A可以把在表mytab的select權(quán)限賦予給B,如果B想也能傳遞該select權(quán)限也可以帶上with grant option
grant select on mytab to B;
登陸EM 的用戶必須有一下權(quán)限
創(chuàng)建了一個(gè)用戶testem,并有如下授權(quán)
create user testem identified by testem;
grant create session,select any dictionary to testem; // testem可以登陸EM,但是還不是em的管理員。
grant MGMT_USER to testem;
非em管理員:(在“管理”下面沒有下圖選項(xiàng))
通過EM 登陸來增加 EM管理員:
名稱:testem
電子郵件地址沒有為此管理員定義電子郵件地址。
有權(quán)訪問所有目標(biāo)的超級(jí)管理員權(quán)限。
數(shù)據(jù)庫系統(tǒng)權(quán)限: SELECT ANY DICTIONARY
數(shù)據(jù)庫角色: MGMT_USER 本文出自:億恩科技【www.laynepeng.cn】
服務(wù)器租用/服務(wù)器托管中國五強(qiáng)!虛擬主機(jī)域名注冊頂級(jí)提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM]
|