Oracle 建立create user 及授權grant

來源:互聯網
上載者:User

查看登陸的使用者:

以下都可以:  
  show   user;  
  select   sys_context('userenv','session_user')   from   dual;  
  select   user   from   dual;    
 
  查看所有登入的使用者必須為DBA 使用者: 
  select   username   from   v$session;

sys、system等DBA 使用者查看 其他使用者(test)中的對象(表):
SQL> select * from test.student;


建立一個普通使用者都把該使用者用起來的流程:
1、建立使用者
SQL>create user test indentified by test;
這樣就建立了一個使用者名稱密碼都為test的使用者
但這個時候test還是不能登陸成功的,我們需要賦予相應的許可權

2、賦予create session的許可權
SQL>grant create session to test;
這樣test使用者就能成功登陸進去

但是此時使用者還是不能建立表 我們需要賦予使用者建立表的許可權:
SQL>grant create table to test;
但是使用者此時還不能建立表 因為需要有使用資料表空間的許可權(相當於 使用者有了進房間的鑰匙 但是沒有進大門的鑰匙。。。)

所以也應該賦予相應的許可權
SQL>grant unlimited tablespace to test;
這個時候使用者就擁有了建立表的許可權 由於表是使用者test的 相應的他就擁有了對建立的表的增刪查改的許可權了

3、查看使用者擁有什麼許可權可以通過查詢一個系統的視圖(數字字典)
SQL>select * from user_sys_privs;
這樣就可以知道目前使用者的許可權

4、撤銷許可權
SQL> revoke create table from test;

-----------------------------
一些常用視圖的區分
dba_tables  dba_all_tables  user_tables  user_all_tables  all_tables  all_all_tables
目前使用者所屬的所有表(注意大寫)
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的使用者建立了個表mytab 並且插入了一些資料
那麼 test使用者是否可以訪問到test1的mytab怎麼訪問?
答:不可以,必須先授權
test1必須授權給test :grant select on mytab to test;
那麼這個時候test可以通過 select * from test1.mytab;來訪問mytab中的資料
如果想把某個表(對象)的所有許可權都賦予給test那麼可以:
grant all on mytab to test;
撤銷所有許可權
revoke all on mytab to test;



總結
對於系統許可權由sys來做
對於對象許可權由 誰擁有誰授權

系統許可權
    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;  //表示把建立表的許可權賦予所有人
   select * from user_sys_privs;  //返回目前使用者的所有系統許可權

對象許可權
    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;  //返回目前使用者所有的對象許可權
  
   對象許可權可以控制到列
   grant update(name) on mytab to test;
   grant insert(id) on mytab to test;

   select * from user_col_privs;
   注意、:查詢和刪除不能控制到列  
    需要有commit的 insert update insert

許可權的傳遞
  系統許可權的傳遞:
   grant alter table to A with admin option;
  那麼A可以通過把該許可權傳遞給B,如果想B也可以傳遞下去那麼可以也帶上with admin option
   grant alter table to B;
  對象許可權的傳遞:
   grant select on mytab to A with grant option;
  那麼A可以把在表mytab的select許可權賦予給B,如果B想也能傳遞該select許可權也可以帶上with grant option
   grant select on mytab to B;
 

登陸EM 的使用者必須有一下許可權
建立了一個使用者testem,並有如下授權
create user testem identified by testem;
grant create session,select any dictionary to testem;  // testem可以登陸EM,但是還不是em的管理員。
grant MGMT_USER to testem;

非em管理員:(在“管理”下面沒有選項)

 
通過EM 登陸來增加 EM管理員:
名稱:testem
電子郵件地址沒有為此管理員定義電子郵件地址。
有權訪問所有目標的超級管理員權限。
資料庫系統許可權: SELECT ANY DICTIONARY
資料庫角色: MGMT_USER

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.