ORACLE 角色授權

來源:互聯網
上載者:User

標籤:

 直接例子:

1.CREATE USER 使用者名稱 identified by 密碼 default tablespace 資料表空間名;
GRANT CONNECT TO 使用者名稱;
GRANT RESOURCE TO 使用者名稱;
grant alter,delete,update,insert,select on 表名 to 使用者名稱;

2.直接用上面的使用者登入PLSQL(例如使用者名稱是User1,密碼是User1,授權的表是Table1,Table1是用system賬戶建立的)

   然後我們發現授權的表名Table1在列表中沒有,用select * from Table1會提示表不存在,那是因為Table1是用system賬戶建立的,不屬於User1。我們要查詢資料需要這樣:

   select * from system.Table1--訪問表資料

   每次都要在表前面加個system.很不方便,我們直接建立一個同義字就可以了。

   create public synonym table_name for user.table_name;       --建立同義字,給user.table_name起個別名叫table_name

   同義字從字面上理解就是別名的意思,和視圖的功能類似,就是一種映射關係。

 

  下面是相關說明:

   一、建立

  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;刪除角色

      轉自:http://www.cnblogs.com/shlcn/archive/2011/07/21/2112879.html

 

  十、密碼重設

SQL>alter user scott identified by password;       //password是自己要設定的密碼,最好以字母開頭

但是如果sys和system密碼忘怎麼辦呢,也可以進行修改

方法如下:

開啟運行,輸入 

sqlplus /nolog

開啟了Oracle的控制台,輸入

conn /as sysdba;       會提示已串連    

然後就像修改普通使用者那樣修改密碼了

SQL>alter user system identified by password;       //password是自己要設定的密碼,最好以字母開頭

轉自:http://www.cnblogs.com/zyw-205520/archive/2012/12/23/2829928.html

ORACLE 角色授權

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.