Javailable学习Oracle数据库用户、权限、角色管理

转载:https://blog.csdn.net/haiross/article/details/50904988

Oracle用户、权限、角色管理


前言:
系统权限是用户用于创建删除以及修改本用户内的数据库对象时用到的;
对象权限是本用户用于修改(以及创建删除)别人用户内的数据库对象时用到的;
当前用户下执行的grant语句,其所能grant的权限都是当前用户本身所拥有的权限。


总结: 
 1. with admin option与with grant option区别:   
- with admin option 只能在赋予 system privilege 的时使用 
- with grant option 只能在赋予 object privilege 的时使用 
  2. 撤消带有admin option 的system privileges 时,连带的权限将保留
3、grant all on 对象名 to public 开放该对象上的当前用户所拥有的所有权限给所有用户。

Oracle 数据库用户管理

Oracle 权限设置
一、权限分类:
系统权限:系统规定用户使用数据库的权限。(系统权限是对用户而言)。

实体权限:某种权限用户对其它用户的表或视图的存取权限。(是针对表或视图而言的)。

二、系统权限管理:
1、系统权限分类:
DBA: 拥有全部特权,是系统最高权限,只有DBA才可以创建数据库结构。

RESOURCE:拥有Resource权限的用户只可以创建实体,不可以创建数据库结构。

CONNECT:拥有Connect权限的用户只可以登录Oracle,不可以创建实体,不可以创建数据库结构。

对于普通用户:授予connect, resource权限。
对于DBA管理用户:授予connect,resource, dba权限。

2、系统权限授权命令:
[系统权限只能由DBA用户授出:sys, system(最开始只能是这两个用户)]
授权命令:SQL> grant connect, resource, dba to 用户名1 [,用户名2]…;

[普通用户通过授权可以具有与system相同的用户权限,但永远不能达到与sys用户相同的权限,system用户的权限也可以被回收。]

例:
SQL> connect system/manager
SQL> Create user user50 identified by user50;
SQL> grant connect, resource to user50;

查询用户拥有哪里权限:
SQL> select * from dba_role_privs;
SQL> select * from dba_sys_privs;
SQL> select * from role_sys_privs;

删除用户:SQL> drop user 用户名 cascade;  //加上cascade则将用户连同其创建的东西全部删除

3、系统权限传递:
增加WITH ADMIN OPTION选项,则得到的权限可以传递。

SQL> grant connect, resorce to user50 with admin option;  //可以传递所获权限。

4、系统权限回收:系统权限只能由DBA用户回收
命令:SQL> Revoke connect, resource from user50;

系统权限无级联,即A授予B权限,B授予C权限,如果A收回B的权限,C的权限不受影响;系统权限可以跨用户回收,即A可以直接收回C用户的权限。

 

sys;//系统管理员,拥有最高权限 
system;//本地管理员,次高权限 
scott;//普通用户,密码默认为tiger,默认未解锁 
sys;//系统管理员,拥有最高权限 
system;//本地管理员,次高权限 
scott;//普通用户,密码默认为tiger,默认未解锁 
二、登陆 

sqlplus / as sysdba;//登陆sys帐户 
sqlplus sys as sysdba;//同上 
sqlplus scott/tiger;//登陆普通用户scott 
sqlplus / as sysdba;//登陆sys帐户 
sqlplus sys as sysdba;//同上 
sqlplus scott/tiger;//登陆普通用户scott 
三、管理用户 

create user zhangsan;//在管理员帐户下,创建用户zhangsan 
alert user scott identified by tiger;//修改密码 
create user zhangsan;//在管理员帐户下,创建用户zhangsan 
alert user scott identified by tiger;//修改密码 
四,授予权限 
1、默认的普通用户scott默认未解锁,不能进行那个使用,新建的用户也没有任何权限,必须授予权限 

/*管理员授权*/ 
grant create session to zhangsan;//授予zhangsan用户创建session的权限,即登陆权限 
grant unlimited session to zhangsan;//授予zhangsan用户使用表空间的权限 
grant create table to zhangsan;//授予创建表的权限 
grante drop table to zhangsan;//授予删除表的权限 
grant insert table to zhangsan;//插入表的权限 
grant update table to zhangsan;//修改表的权限 
grant all to public;//这条比较重要,授予所有权限(all)给所有用户(public) 
/*管理员授权*/ 
grant create session to zhangsan;//授予zhangsan用户创建session的权限,即登陆权限 
grant unlimited session to zhangsan;//授予zhangsan用户使用表空间的权限 
grant create table to zhangsan;//授予创建表的权限 
grante drop table to zhangsan;//授予删除表的权限 
grant insert table to zhangsan;//插入表的权限 
grant update table to zhangsan;//修改表的权限 
grant all to public;//这条比较重要,授予所有权限(all)给所有用户(public) 
2、oralce对权限管理比较严谨,普通用户之间也是默认不能互相访问的,需要互相授权 

/*oralce对权限管理比较严谨,普通用户之间也是默认不能互相访问的*/ 
grant select on tablename to zhangsan;//授予zhangsan用户查看指定表的权限 
grant drop on tablename to zhangsan;//授予删除表的权限 
grant insert on tablename to zhangsan;//授予插入的权限 
grant update on tablename to zhangsan;//授予修改表的权限 
grant insert(id) on tablename to zhangsan; 
grant update(id) on tablename to zhangsan;//授予对指定表特定字段的插入和修改权限,注意,只能是insert和update 
grant alert all table to zhangsan;//授予zhangsan用户alert任意表的权限 
/*oralce对权限管理比较严谨,普通用户之间也是默认不能互相访问的*/ 
grant select on tablename to zhangsan;//授予zhangsan用户查看指定表的权限 
grant drop on tablename to zhangsan;//授予删除表的权限 
grant insert on tablename to zhangsan;//授予插入的权限 
grant update on tablename to zhangsan;//授予修改表的权限 
grant insert(id) on tablename to zhangsan; 
grant update(id) on tablename to zhangsan;//授予对指定表特定字段的插入和修改权限,注意,只能是insert和update 
grant alert all table to zhangsan;//授予zhangsan用户alert任意表的权限 
五、撤销权限 

基本语法同grant,关键字为revoke 
基本语法同grant,关键字为revoke 
六、查看权限 

select * from user_sys_privs;//查看当前用户所有权限 
select * from user_tab_privs;//查看所用用户对表的权限 
select * from user_sys_privs;//查看当前用户所有权限 
select * from user_tab_privs;//查看所用用户对表的权限 
七、操作表的用户的表 

/*需要在表名前加上用户名,如下*/ 
select * from zhangsan.tablename 
/*需要在表名前加上用户名,如下*/ 
select * from zhangsan.tablename 

八、权限传递 
即用户A将权限授予B,B可以将操作的权限再授予C,命令如下: 

grant alert table on tablename to zhangsan with admin option;//关键字 with admin option 
grant alert table on tablename to zhangsan with grant option;//关键字 with grant option效果和admin类似 
grant alert table on tablename to zhangsan with admin option;//关键字 with admin option 
grant alert table on tablename to zhangsan with grant option;//关键字 with grant option效果和admin类似 
九、角色 
角色即权限的集合,可以把一个角色授予给用户 

create role myrole;//创建角色 
grant create session to myrole;//将创建session的权限授予myrole 
grant myrole to zhangsan;//授予zhangsan用户myrole的角色 
drop role myrole;删除角色 
/*但是有些权限是不能授予给角色的,比如unlimited tablespace和any关键字*/

参考: oracle grant 授权语句 百度

====================================

权限:

  create session

  create table

  unlimited tablespace

  connect

  resource

  dba

  例:

  #sqlplus /nolog

  SQL> conn / as sysdba;

  SQL>create user username identified by password

  SQL> grant dba to username;

  SQL> conn username/password

  SQL> select * from user_sys_privs;

  我们将从创建Oracle用户权限表开始谈起,然后讲解登陆等一般性动作,使大家对Oracle用户权限表有个深入的了解。

  一、创建

  sys;//系统管理员,拥有最高权限

  system;//本地管理员,次高权限

  scott;//普通用户,密码默认为tiger,默认未解锁

  二、登陆

  sqlplus / as sysdba;//登陆sys帐户

  sqlplus sys as sysdba;//同上

  sqlplus scott/tiger;//登陆普通用户scott

  三、管理用户

  create user zhangsan;//在管理员帐户下,创建用户zhangsan

  alert user scott identified by tiger;//修改密码

  四,授予权限

  1、默认的普通用户scott默认未解锁,不能进行那个使用,新建的用户也没有任何权限,必须授予权限

  

  grant create session to zhangsan;//授予zhangsan用户创建session的权限,即登陆权限

  grant unlimited tablespace to zhangsan;//授予zhangsan用户使用表空间的权限

  grant create table to zhangsan;//授予创建表的权限

  grante drop table to zhangsan;//授予删除表的权限

  grant insert table to zhangsan;//插入表的权限

  grant update table to zhangsan;//修改表的权限

  grant all to public;//这条比较重要,授予所有权限(all)给所有用户(public)

  2、oralce对权限管理比较严谨,普通用户之间也是默认不能互相访问的,需要互相授权

  

  grant select on tablename to zhangsan;//授予zhangsan用户查看指定表的权限

  grant drop on tablename to zhangsan;//授予删除表的权限

  grant insert on tablename to zhangsan;//授予插入的权限

  grant update on tablename to zhangsan;//授予修改表的权限

  grant insert(id) on tablename to zhangsan;

  grant update(id) on tablename to zhangsan;//授予对指定表特定字段的插入和修改权限,注意,只能是insert和update

  grant alert all table to zhangsan;//授予zhangsan用户alert任意表的权限

  五、撤销权限

  基本语法同grant,关键字为revoke

  六、查看权限

  select * from user_sys_privs;//查看当前用户所有权限

  select * from user_tab_privs;//查看所用用户对表的权限

  七、操作表的用户的表

  

  select * from zhangsan.tablename

  八、权限传递

  即用户A将权限授予B,B可以将操作的权限再授予C,命令如下:

  grant alert table on tablename to zhangsan with admin option;//关键字 with admin option

  grant alert table on tablename to zhangsan with grant option;//关键字 with grant option效果和admin类似

  九、角色

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

  create role myrole;//创建角色

  grant create session to myrole;//将创建session的权限授予myrole

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

  drop role myrole;删除角色





Oracle用户、权限、角色管理


前言:
系统权限是用户用于创建删除以及修改本用户内的数据库对象时用到的;
对象权限是本用户用于修改(以及创建删除)别人用户内的数据库对象时用到的;
当前用户下执行的grant语句,其所能grant的权限都是当前用户本身所拥有的权限。


总结: 
 1. with admin option与with grant option区别:   
- with admin option 只能在赋予 system privilege 的时使用 
- with grant option 只能在赋予 object privilege 的时使用 
  2. 撤消带有admin option 的system privileges 时,连带的权限将保留
3、grant all on 对象名 to public 开放该对象上的当前用户所拥有的所有权限给所有用户。

Oracle 数据库用户管理

Oracle 权限设置
一、权限分类:
系统权限:系统规定用户使用数据库的权限。(系统权限是对用户而言)。

实体权限:某种权限用户对其它用户的表或视图的存取权限。(是针对表或视图而言的)。

二、系统权限管理:
1、系统权限分类:
DBA: 拥有全部特权,是系统最高权限,只有DBA才可以创建数据库结构。

RESOURCE:拥有Resource权限的用户只可以创建实体,不可以创建数据库结构。

CONNECT:拥有Connect权限的用户只可以登录Oracle,不可以创建实体,不可以创建数据库结构。

对于普通用户:授予connect, resource权限。
对于DBA管理用户:授予connect,resource, dba权限。

2、系统权限授权命令:
[系统权限只能由DBA用户授出:sys, system(最开始只能是这两个用户)]
授权命令:SQL> grant connect, resource, dba to 用户名1 [,用户名2]…;

[普通用户通过授权可以具有与system相同的用户权限,但永远不能达到与sys用户相同的权限,system用户的权限也可以被回收。]

例:
SQL> connect system/manager
SQL> Create user user50 identified by user50;
SQL> grant connect, resource to user50;

查询用户拥有哪里权限:
SQL> select * from dba_role_privs;
SQL> select * from dba_sys_privs;
SQL> select * from role_sys_privs;

删除用户:SQL> drop user 用户名 cascade;  //加上cascade则将用户连同其创建的东西全部删除

3、系统权限传递:
增加WITH ADMIN OPTION选项,则得到的权限可以传递。

SQL> grant connect, resorce to user50 with admin option;  //可以传递所获权限。

4、系统权限回收:系统权限只能由DBA用户回收
命令:SQL> Revoke connect, resource from user50;

系统权限无级联,即A授予B权限,B授予C权限,如果A收回B的权限,C的权限不受影响;系统权限可以跨用户回收,即A可以直接收回C用户的权限。

 

sys;//系统管理员,拥有最高权限 
system;//本地管理员,次高权限 
scott;//普通用户,密码默认为tiger,默认未解锁 
sys;//系统管理员,拥有最高权限 
system;//本地管理员,次高权限 
scott;//普通用户,密码默认为tiger,默认未解锁 
二、登陆 

sqlplus / as sysdba;//登陆sys帐户 
sqlplus sys as sysdba;//同上 
sqlplus scott/tiger;//登陆普通用户scott 
sqlplus / as sysdba;//登陆sys帐户 
sqlplus sys as sysdba;//同上 
sqlplus scott/tiger;//登陆普通用户scott 
三、管理用户 

create user zhangsan;//在管理员帐户下,创建用户zhangsan 
alert user scott identified by tiger;//修改密码 
create user zhangsan;//在管理员帐户下,创建用户zhangsan 
alert user scott identified by tiger;//修改密码 
四,授予权限 
1、默认的普通用户scott默认未解锁,不能进行那个使用,新建的用户也没有任何权限,必须授予权限 

/*管理员授权*/ 
grant create session to zhangsan;//授予zhangsan用户创建session的权限,即登陆权限 
grant unlimited session to zhangsan;//授予zhangsan用户使用表空间的权限 
grant create table to zhangsan;//授予创建表的权限 
grante drop table to zhangsan;//授予删除表的权限 
grant insert table to zhangsan;//插入表的权限 
grant update table to zhangsan;//修改表的权限 
grant all to public;//这条比较重要,授予所有权限(all)给所有用户(public) 
/*管理员授权*/ 
grant create session to zhangsan;//授予zhangsan用户创建session的权限,即登陆权限 
grant unlimited session to zhangsan;//授予zhangsan用户使用表空间的权限 
grant create table to zhangsan;//授予创建表的权限 
grante drop table to zhangsan;//授予删除表的权限 
grant insert table to zhangsan;//插入表的权限 
grant update table to zhangsan;//修改表的权限 
grant all to public;//这条比较重要,授予所有权限(all)给所有用户(public) 
2、oralce对权限管理比较严谨,普通用户之间也是默认不能互相访问的,需要互相授权 

/*oralce对权限管理比较严谨,普通用户之间也是默认不能互相访问的*/ 
grant select on tablename to zhangsan;//授予zhangsan用户查看指定表的权限 
grant drop on tablename to zhangsan;//授予删除表的权限 
grant insert on tablename to zhangsan;//授予插入的权限 
grant update on tablename to zhangsan;//授予修改表的权限 
grant insert(id) on tablename to zhangsan; 
grant update(id) on tablename to zhangsan;//授予对指定表特定字段的插入和修改权限,注意,只能是insert和update 
grant alert all table to zhangsan;//授予zhangsan用户alert任意表的权限 
/*oralce对权限管理比较严谨,普通用户之间也是默认不能互相访问的*/ 
grant select on tablename to zhangsan;//授予zhangsan用户查看指定表的权限 
grant drop on tablename to zhangsan;//授予删除表的权限 
grant insert on tablename to zhangsan;//授予插入的权限 
grant update on tablename to zhangsan;//授予修改表的权限 
grant insert(id) on tablename to zhangsan; 
grant update(id) on tablename to zhangsan;//授予对指定表特定字段的插入和修改权限,注意,只能是insert和update 
grant alert all table to zhangsan;//授予zhangsan用户alert任意表的权限 
五、撤销权限 

基本语法同grant,关键字为revoke 
基本语法同grant,关键字为revoke 
六、查看权限 

select * from user_sys_privs;//查看当前用户所有权限 
select * from user_tab_privs;//查看所用用户对表的权限 
select * from user_sys_privs;//查看当前用户所有权限 
select * from user_tab_privs;//查看所用用户对表的权限 
七、操作表的用户的表 

/*需要在表名前加上用户名,如下*/ 
select * from zhangsan.tablename 
/*需要在表名前加上用户名,如下*/ 
select * from zhangsan.tablename 

八、权限传递 
即用户A将权限授予B,B可以将操作的权限再授予C,命令如下: 

grant alert table on tablename to zhangsan with admin option;//关键字 with admin option 
grant alert table on tablename to zhangsan with grant option;//关键字 with grant option效果和admin类似 
grant alert table on tablename to zhangsan with admin option;//关键字 with admin option 
grant alert table on tablename to zhangsan with grant option;//关键字 with grant option效果和admin类似 
九、角色 
角色即权限的集合,可以把一个角色授予给用户 

create role myrole;//创建角色 
grant create session to myrole;//将创建session的权限授予myrole 
grant myrole to zhangsan;//授予zhangsan用户myrole的角色 
drop role myrole;删除角色 
/*但是有些权限是不能授予给角色的,比如unlimited tablespace和any关键字*/

参考: oracle grant 授权语句 百度

====================================

权限:

  create session

  create table

  unlimited tablespace

  connect

  resource

  dba

  例:

  #sqlplus /nolog

  SQL> conn / as sysdba;

  SQL>create user username identified by password

  SQL> grant dba to username;

  SQL> conn username/password

  SQL> select * from user_sys_privs;

  我们将从创建Oracle用户权限表开始谈起,然后讲解登陆等一般性动作,使大家对Oracle用户权限表有个深入的了解。

  一、创建

  sys;//系统管理员,拥有最高权限

  system;//本地管理员,次高权限

  scott;//普通用户,密码默认为tiger,默认未解锁

  二、登陆

  sqlplus / as sysdba;//登陆sys帐户

  sqlplus sys as sysdba;//同上

  sqlplus scott/tiger;//登陆普通用户scott

  三、管理用户

  create user zhangsan;//在管理员帐户下,创建用户zhangsan

  alert user scott identified by tiger;//修改密码

  四,授予权限

  1、默认的普通用户scott默认未解锁,不能进行那个使用,新建的用户也没有任何权限,必须授予权限

  

  grant create session to zhangsan;//授予zhangsan用户创建session的权限,即登陆权限

  grant unlimited tablespace to zhangsan;//授予zhangsan用户使用表空间的权限

  grant create table to zhangsan;//授予创建表的权限

  grante drop table to zhangsan;//授予删除表的权限

  grant insert table to zhangsan;//插入表的权限

  grant update table to zhangsan;//修改表的权限

  grant all to public;//这条比较重要,授予所有权限(all)给所有用户(public)

  2、oralce对权限管理比较严谨,普通用户之间也是默认不能互相访问的,需要互相授权

  

  grant select on tablename to zhangsan;//授予zhangsan用户查看指定表的权限

  grant drop on tablename to zhangsan;//授予删除表的权限

  grant insert on tablename to zhangsan;//授予插入的权限

  grant update on tablename to zhangsan;//授予修改表的权限

  grant insert(id) on tablename to zhangsan;

  grant update(id) on tablename to zhangsan;//授予对指定表特定字段的插入和修改权限,注意,只能是insert和update

  grant alert all table to zhangsan;//授予zhangsan用户alert任意表的权限

  五、撤销权限

  基本语法同grant,关键字为revoke

  六、查看权限

  select * from user_sys_privs;//查看当前用户所有权限

  select * from user_tab_privs;//查看所用用户对表的权限

  七、操作表的用户的表

  

  select * from zhangsan.tablename

  八、权限传递

  即用户A将权限授予B,B可以将操作的权限再授予C,命令如下:

  grant alert table on tablename to zhangsan with admin option;//关键字 with admin option

  grant alert table on tablename to zhangsan with grant option;//关键字 with grant option效果和admin类似

  九、角色

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

  create role myrole;//创建角色

  grant create session to myrole;//将创建session的权限授予myrole

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

  drop role myrole;删除角色





猜你喜欢

转载自blog.csdn.net/zz13995900221/article/details/80190366