posts - 15, comments - 20, trackbacks - 0, articles - 6
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          oracle分配權限 學習筆記

          Posted on 2009-09-28 09:41 spinage 閱讀(628) 評論(0)  編輯  收藏

          在全局數據庫ORCL下創建一個用戶
          首先在開始--》運行——》sqlplus,然后輸入 sys/change_on_install as sysdba
          以sys權限登陸進去
          然后可以進行操作:
          創建用戶 create user test indentified by test;
          這樣就創建了一個用戶名密碼都為test的用戶
          但這個時候test還是不能登陸成功的,我們需要賦予相應的權限
          首先賦予create session的權限
          grant create session to test;
          這樣test用戶就能成功登陸進去
          但是此時用戶還是不能創建表 我們需要賦予用戶創建表的權限:
          grant create table to test;
          但是用戶此時還不能創建表 因為需要有使用表空間的權限(相當于 用戶有了進房間的鑰匙 但是沒有進大門的鑰匙)
          所以也應該賦予相應的權限
          grant unlimited tablespace to test;
          這個時候用戶就擁有了創建表的權限 由于表是用戶test的 相應的他就擁有了對創建的表的增刪查改的權限了
          我們要查看用戶擁有什么權限可以通過查詢一個系統的視圖(數字字典)
          select * from user_sys_privs;
          這樣就可以知道當前用戶的權限

          撤銷權限 revoke create table from test;

          場景:
          用戶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;

             
             對象權限可以控制到列 (更新和插入操作)
             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;

          ----------------------------------------------------------------------------------------------------------

          --創建用戶
          create user keeltest identified by keeltest;
          --分配權限
          grant create session,create table,create view ,create any index to keeltest;
          grant unlimited tablespace to keeltest;

           


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 梁平县| 柳江县| 保亭| 博爱县| 栾川县| 内丘县| 广宁县| 宁强县| 绥中县| 博爱县| 广饶县| 稻城县| 湘乡市| 金阳县| 隆昌县| 思南县| 西吉县| 张掖市| 石渠县| 龙游县| 沙湾县| 南丰县| 万年县| 霍城县| 靖安县| 泽普县| 南江县| 梨树县| 永川市| 海安县| 大足县| 如皋市| 札达县| 富裕县| 咸丰县| 阿合奇县| 汾阳市| 海盐县| 龙游县| 江陵县| 越西县|