zoukankan      html  css  js  c++  java
  • Oracle 根据业务创建新的用户

    新的需求,创建一个用户,可以查询基表的数据,但是不能修改,同时自己也可以创建对象


    1.创建用户
    第一种方式 详细常见,前提 表空间和临时表空间必须存在

    格式:
    create user 用户名 identified by 密码
    profile default
    default tablespace 表空间名(一般就是users)
    temporary tablespace 临时表空间名(各不相同)
    account unlock;

    例子:
    SQL> create user sun identified by xxxx
    2 profile default
    3 default tablespace users
    4 temporary tablespace tempts01
    5 account unlock;

    第二种方式 默认创建(系统爱建哪建哪)

    格式:
    create user 用户名 identified by 密码;

    例子:
    SQL> create user sun identified by xxxx;

    用户已创建。

    2.授权

    创建好了之后直接登陆报错,因为没有权限

    例子:
    SQL> conn sun/xxxx

    ERROR:
    ORA-01045: user SUN lacks CREATE SESSION privilege; logon denied

    连接sys用户,授权


    SQL> conn / as sysdba
    已连接。

    说明connect,resource是基础权限
    SQL> grant connect,resource to sun;

    授权成功。

    再次链接,成功,并查询用户拥有权限
    SQL> conn sun/xxxx
    已连接。

    SQL> select * from user_role_privs;

    USERNAME GRANTED_ROLE ADMIN_ DEFAUL OS_GRA
    ------------------------------------------------------------ ------------------------------------------------------------ ------ ------ ------
    SUN CONNECT NO YES NO
    SUN RESOURCE NO YES NO

    3.实现业务需要,基础数据不变,但各自产生的数据再各自的表中
    sun用户为新用户
    scott用下面的表为基础表,可查询,不能修改

    业务一:查看基表数据
    SQL> conn scott/xxxx
    已连接。
    SQL> select table_name from user_tables;

    TABLE_NAME
    ------------------------------------------------------------
    DEPT
    EMP
    BONUS
    SALGRADE
    TEST

    将scott下的dept表的查询权限授予sun,实现可以查询基础表数据的功能
    SQL> conn / as sysdba
    已连接。
    SQL> grant select on scott.dept to sun;

    授权成功。


    测试一下
    SQL> conn sun/xxxx
    已连接。

    SQL> select * from dept;
    select * from dept
    *
    第 1 行出现错误:
    ORA-00942: 表或视图不存在
    这个错误是因为没有指定用户名,默认是在自己的用户下查找

    再次查找,成功,帅气!
    SQL> select * from scott.dept;

    DEPTNO DNAME LOC
    ---------- ---------------------------- --------------------------
    10 ACCOUNTING NEW YORK
    20 RESEARCH DALLAS
    30 SALES CHICAGO
    40 OPERATIONS BOSTON

    查找其他的表,不成功,因为没有授权
    SQL> select * from scott.emp;
    select * from scott.emp
    *
    第 1 行出现错误:
    ORA-00942: 表或视图不存在

    我们查询一下sun用户的权限
    SQL> select * from user_tab_privs;

    GRANTEE OWNER TABLE_NAME GRANTOR PRIVILEGE GRANTA HIERAR

    ---------- -------- ------------- ---------- ----------- --------- --------
          SUN    SCOTT            DEPT      SCOTT     SELECT         NO        NO

    业务二:用户自己可以创建对象

    授权:
    grant create any produce to 用户名;
    grant create any sequence to 用户名;
    grant create any view to 用户名;
    grant create any synonym to 用户名;

  • 相关阅读:
    关于client浏览器界面文字内容溢出用省略号表示方法
    Oracle 11gR2光钎链路切换crs服务发生crash
    制作U盘启动盘将Ubuntu 12.04升级为14.04的方法
    Android图片处理——压缩、剪裁、圆角、保存
    安卓使用WebView下载文件,安卓实现软件升级功能
    Android仿Win8界面的button点击
    Chormium线程模型及应用指南
    POJ 3436 ACM Computer Factory 最大流
    hdu 3547 DIY Cube (Ploya定理)
    ant安装配置问题:ANT_HOME is set incorrectly or ant could not be located. Please set ANT_HOME.
  • 原文地址:https://www.cnblogs.com/SUN-PH/p/4024264.html
Copyright © 2011-2022 走看看