在全局?jǐn)?shù)據(jù)庫ORCL下創(chuàng)建一個用戶
首先在開始--》運(yùn)行——》sqlplus,然后輸入 sys/change_on_install as sysdba
以system權(quán)限登陸進(jìn)去
然后可以進(jìn)行操作:
創(chuàng)建用戶 create user test indentified by test;
這樣就創(chuàng)建了一個用戶名密碼都為test的用戶
但這個時(shí)候test還是不能登陸成功的,我們需要賦予相應(yīng)的權(quán)限
首先賦予create session的權(quán)限
grant create session to test;
這樣test用戶就能成功登陸進(jìn)去
但是此時(shí)用戶還是不能創(chuàng)建表 我們需要賦予用戶創(chuàng)建表的權(quán)限:
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)限
grant unlimited tablespace to test;
這個時(shí)候用戶就擁有了創(chuàng)建表的權(quán)限 由于表是用戶test的 相應(yīng)的他就擁有了對創(chuàng)建的表的增刪查改的權(quán)限了
我們要查看用戶擁有什么權(quán)限可以通過查詢一個系統(tǒng)的視圖(數(shù)字字典)
select * from user_sys_privs;
這樣就可以知道當(dāng)前用戶的權(quán)限
撤銷權(quán)限 revoke create table from test;
場景:
用戶test 用戶test1
test1的用戶創(chuàng)建了個表mytab 并且插入了一些數(shù)據(jù)
那么 test用戶是否可以訪問到test1的mytab怎么訪問?
答:不可以,必須先授權(quán)
test1必須授權(quán)給test :grant select on mytab to test;
那么這個時(shí)候test可以通過 select * from test1.mytab;來訪問mytab中的數(shù)據(jù)
如果想把某個表(對象)的所有權(quán)限都賦予給test那么可以:
grant all on mytab to test;
撤銷所有權(quán)限
revoke all on mytab to test;
總結(jié):
對于系統(tǒng)權(quán)限由sys來做
對于對象權(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)限
grant select on mytab to test;
grant all on mytab to test;
revoke select on mytab from test;
revoke all on mytab from test;
對象權(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;
對象權(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;
--------------------------------------------------------------------------------------------------
--創(chuàng)建用戶
create user keeltest identified by keeltest;
--分配權(quán)限
grant create session,create table,create view ,create any index to keeltest;
grant unlimited tablespace to keeltest;