• oracle的用户权限和角色


        oracle的用户权限和角色

    系统权限

      定义:指特定类型的sql命令的权利。

      常见的有:

      create  session  连接数据库

      create   table    建表

      create    view    建视

      create  public  synonym  建同义词

      create procedure  建过程、函数、包

      create trigger    建触发器   

      create cluster   建簇

    如何使用select来查询有哪些系统权限

      select * from system_privilege_map order by name;

    案例:

     

       1.创建两个用户并指定密码

         connect system/orcl;

         create user ken identified by ken;

         create user tom identified by tom;

      2.给ken 授予会话,建表,建视图的权限

         grant create session to ken with admin option【有with admin option】

         grant create table to ken with admin option【有with admin option】

         grant create view to ken 【无with admin option】

    3.用ken 给tom赋予相同的权限

       connect  ken/ken;

        grant create session to tom with admin option
        grant create table to tom with admin option

         grant create view to tom   报错!!!!!】  

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

       报错的原因:

         权限的流程:

          system  =》 ken =》 tom

          如何能够赋予他人权限,除system拥有超级权限外,其他用户想要继承赋予他人

          权限的能力,必须在system赋予权限时加入with admin option,才能有赋予权限

          的能力,如上所示在system赋予ken权限时只有创建视图没有加入with adminoption,所以他不能够赋予他人权限,所以报错。

     回收系统权限

    使用system回收ken [create  session   权限]

    基本语法

    revoke 权限名称 from 用户名

    例:

     revoke create session from ken;

    问题:

    在回收ken的权限之后,是否也回收曾经是被ken赋予权限的tom的权限。

     答:不是,只回收指定的权限

    对象权限

    定义:指访问其它方案对象的权利

    oracle 给我们提供17种对象权限,可以通过如下指令,来查看(dba 角色)

    select distinct  privilege from dba_tab_privs;

    基本语法:

    grant 对象权限 on 方案.数据对象 to 用户[with grant option]

    grant 对象权限 on 方案.数据对象 to 角色(角色不能拥有赋予权限的权利)

    案例:

    1.monkey用户要操作scott.emp表,则必须赋予相对应的对象权限

     (1)希望monkey可以查询到scott.emp表中的数据?

          使用scott或者system/sys用户操作

         grant select on scott.emp to monkey;

    (2)希望monkey可以修改到scott.emp表中的数据?

         grant update on scott.emp to monkey;

    (3)希望monkey可以删除到scott.emp表中的数据?

         grant delete on scott.emp to monkey;

    (4)有没有简单的方法,一次性赋予所有权利?

         grant all on scott.emp to monkey;

    2.授予moneky用户修改scott.emp表的结构 权限

       grant alter on scott.emp to monkey;

    3.授予execute权限(概念)

       如果用户想要执行其他方案的包/过程/函数,则需要execute权限。

    4.授予monkey用户在scott.emp表中建立索引的权限?

       connect scott/tiger;

       grant index on scott.emp to monkey;

    回收对象权限:

    基本语法:

    revoke  对象权限 on 方案.数据对象 from 用户

    对象权限是级联回收:因为引用的一个对象,一旦对象消失,就失去了引用。

    scott  =>>>>>  blake =>>>>> jones

    system操作:

    create user blake identified by blake;

    create user jones identified by jones;

    grant create session to blake;

    grant create session to jones;

    使用scott登陆,授予blake查询emp表权限,然后

    再用blake授予jones权限,然后查询emp表

    scott操作

    grant select on emp to blake; 

    blake操作

    grant select on scott.emp to jones;

    此时,两张表都可查询emp表

    注意:

    scott操作

      revoke select on emp from blake;    --回收权限

    此时,两张表都不可查询emp表

    角色

    定义:角色是一组权限的集合,目的是为了简化对权限的管理,从而达到简单的对用户的管理。

    角色的分类

      (1)预定义角色:

              oracle提供了33种预定义角色,常用的是(connect,dba,resource);

      ?如何知道某个角色拥有怎样的权限

         select * from dba_sys_privs where grantee = ‘DBA’;

      ?如何知道某个用户拥有什么样的权限

         select * from dba_role_privs where grantee = ‘用户名’;

       注:角色名称一定大写

    (2)自定义角色:

         基本语法:

           不带验证:

            create role 角色名 not identified;

                   带验证:

                    create role 角色名 identified by 密码;
    案例:

    创建角色:

     create role myrole not identified;

    赋予角色权利:

     系统权限:

     grant create session to myrole;

     对象权限(scott.emp)

     grant select on scott.emp to myrole;

     grant insert on scott.emp to myrole;

     grant update on scott.emp to myrole;

    赋予用户角色:

     create user jerry identified by  jerry;

     grant myrole to jerry;

    回收角色:

    drop role mylore;

    范围:角色既可以包含系统角色,也可以包含自定义角色。

  • 相关阅读:
    业余时间决定人生
    单片机好网站
    坚持 放弃
    励志博客园网址
    资料下载好网站
    和易法
    二、栈
    一、顺序表
    uCOS任务中的OSTCBDly
    三(1)、队列(链队列)
  • 原文地址:https://www.cnblogs.com/w-gao/p/7335195.html
Copyright © 2020-2023  润新知