oracle创建,查看用户和角色,用户角色赋权

一、创建用户并赋予权限

1、创建用户

create user wangxiangyu identified by wangxiangyu;

2、赋权

grant dba to wangxiangyu;

grant create session to wangxiangyu; --会话权限(没有该权限无法登录)

3、查看已经赋予用户的系统权限

select * from user_sys_privs;

二、创建角色

角色,即权限的集合,可以把一个角色授予给用户

1、创建角色

create role myrole;

2、赋权

grant create session to myrole;--将创建session的权限授予给角色myrole

3、赋角色给用户

grant myrole to zhangsan;--授予zhangsan用户myrole的角色

4、删除角色

drop role myrole;

查看所有用户

select * from dba_users;

select * from all_users;

select * from user_users;

alter user user_name account lock; 锁住用户

alter user user_name account unlock; 解锁用户

查询当前用户所拥有的权限

select * from session_privs;

查看用户被赋予的系统权限(直接赋值给用户或角色的系统权限)

select * from dba_sys_privs where grantee = 'RESOURCE';

select * from user_sys_privs;

注:USER_SYS_PRIVS 视图列出已经授予用户的系统权限。

它的列包括Username、Privilege和 Admin_Option(设置为YES 或NO 的一个标志,用来指出是否用with admin option 授予权限),直接授予用户的所有系统权限都可以通过该视图显示,通过角色授予用户的系统权限不能在此视图中显示。

查看所有角色

select * from dba_roles;

查看用户所拥有的角色

select * from session_roles order by role;--返回当前用户被授予的全部角色, 包括嵌套授权的角色

select * from dba_role_privs;

select * from user_role_privs;

查看当前用户角色所包含的权限

select * from role_sys_privs where role = 'CONNECT';

查看用户对象权限

select * from dba_tab_privs;

select * from all_tab_privs;

select * from user_tab_privs;

查看哪些用户有sysdba或sysoper系统权限(查询时需要相应权限)

select * from v$pwfile_users;

查看用户与默认表空间的关系

select username, default_tablespace from dba_users where username='SCOTT';

查看当前用户的表

select * from user_tables;

可视化赋权:

1、使用ins用户建表

2、使用mobapp用户(管理员)将ins用户的某个表赋权给odso用户

users——>ins,选中要赋权的表赋权(右键,编辑,权限)

等同于:grant select, insert, update, delete on ins.tb_cablecheck_equ_odso to odso;

3、使用odso用户登录,增删改查该表测试

命令赋权:

赋予权限:grant ... to ...

撤销权限:revoke ... from ...

登陆

grant create session to zhangsan;

使用表空间

grant unlimited tablespace to zhangsan;

创建表

grant create table to zhangsan;

删除表

grant drop table to zhangsan;

grant drop on table_name to user_name;

插入表

grant insert table to zhangsan;

grant insert on table_name to user_name;

grant insert(id) on table_name to user_name;

更新表数据

grant update table to zhangsan;

grant update on table_name to user_name;

grant update(id) on table_name to user_name;

修改表结构

grant alter table on table_name to user_name;

查询表

grant select on table_name to user_name;

创建过程

grant create any procedure to username;

执行过程

grant execute any procedure to username;

grant execute on ins.p_trun_link_odso  to odso_insert;

授予所有权限(all)给所有用户(public)

grant all to public;

权限传递

即用户A将权限授予B,B可以将操作的权限再授予C,

命令如下:

grant alter table on table_name to user_name with admin option;

grant update on table_name to user_name with grant option; --转移更新权限

grant alter table on table_name to user_name with grant option;

猜你喜欢

转载自www.cnblogs.com/xyhero/p/7c9248100e6d104febda1038db3870d7.html