始创于2000年 股票代码:831685
咨询热线:0371-60135900 注册有礼 登录
  • 挂牌上市企业
  • 60秒人工响应
  • 99.99%连通率
  • 7*24h人工
  • 故障100倍补偿
您的位置: 网站首页 > 帮助中心>文章内容

Oracle 创建create user 及授权grant

发布时间:  2012/9/3 16:49:35

查看登陆的用户:

以下都可以: 
  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


本文出自:亿恩科技【www.enkj.com】

服务器租用/服务器托管中国五强!虚拟主机域名注册顶级提供商!15年品质保障!--亿恩科技[ENKJ.COM]

  • 您可能在找
  • 亿恩北京公司:
  • 经营性ICP/ISP证:京B2-20150015
  • 亿恩郑州公司:
  • 经营性ICP/ISP/IDC证:豫B1.B2-20060070
  • 亿恩南昌公司:
  • 经营性ICP/ISP证:赣B2-20080012
  • 服务器/云主机 24小时售后服务电话:0371-60135900
  • 虚拟主机/智能建站 24小时售后服务电话:0371-60135900
  • 专注服务器托管17年
    扫扫关注-微信公众号
    0371-60135900
    Copyright© 1999-2019 ENKJ All Rights Reserved 亿恩科技 版权所有  地址:郑州市高新区翠竹街1号总部企业基地亿恩大厦  法律顾问:河南亚太人律师事务所郝建锋、杜慧月律师   京公网安备41019702002023号
      0
     
     
     
     

    0371-60135900
    7*24小时客服服务热线