Oracle 数据库用户管理sql
Oracle 权限设置
1、权限分类:
系统权限:系统规定用户使用数据库的权限。(系统权限是对用户而言)。数据库
实体权限:某种权限用户对其它用户的表或视图的存取权限。(是针对表或视图而言的)。session
2、系统权限管理:
一、系统权限分类:
DBA: 拥有所有特权,是系统最高权限,只有DBA才能够建立数据库结构。ide
RESOURCE:拥有Resource权限的用户只能够建立实体,不能够建立数据库结构。spa
CONNECT:拥有Connect权限的用户只能够登陆Oracle,不能够建立实体,不能够建立数据库结构。it
对于普通用户:授予connect, resource权限。
对于DBA管理用户:授予connect,resource, dba权限。io
二、系统权限受权命令:
[系统权限只能由DBA用户授出:sys, system(最开始只能是这两个用户)]
受权命令:SQL> grant connect, resource, dba to 用户名1 [,用户名2]...;table
[普通用户经过受权能够具备与system相同的用户权限,但永远不能达到与sys用户相同的权限,system用户的权限也能够被回收。]登录
例:
SQL> connect system/manager
SQL> Create user user50 identified by user50;
SQL> grant connect, resource to user50;date
查询用户拥有哪里权限:
SQL> select * from dba_role_privs;
SQL> select * from dba_sys_privs;
SQL> select * from role_sys_privs;
删除用户:SQL> drop user 用户名 cascade; //加上cascade则将用户连同其建立的东西所有删除
三、系统权限传递:
增长WITH ADMIN OPTION选项,则获得的权限能够传递。
SQL> grant connect, resorce to user50 with admin option; //能够传递所获权限。
四、系统权限回收:系统权限只能由DBA用户回收
命令:SQL> Revoke connect, resource from user50;
系统权限无级联,即A授予B权限,B授予C权限,若是A收回B的权限,C的权限不受影响;系统权限能够跨用户回收,即A能够直接收回C用户的权限。
sys;//系统管理员,拥有最高权限
system;//本地管理员,次高权限
scott;//普通用户,密码默认为tiger,默认未解锁
sys;//系统管理员,拥有最高权限
system;//本地管理员,次高权限
scott;//普通用户,密码默认为tiger,默认未解锁
2、登录
sqlplus / as sysdba;//登录sys账户
sqlplus sys as sysdba;//同上
sqlplus scott/tiger;//登录普通用户scott
sqlplus / as sysdba;//登录sys账户
sqlplus sys as sysdba;//同上
sqlplus scott/tiger;//登录普通用户scott
3、管理用户
create user zhangsan;//在管理员账户下,建立用户zhangsan
alert user scott identified by tiger;//修改密码
create user zhangsan;//在管理员账户下,建立用户zhangsan
alert user scott identified by tiger;//修改密码
四,授予权限
一、默认的普通用户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)
二、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任意表的权限
5、撤销权限
基本语法同grant,关键字为revoke
基本语法同grant,关键字为revoke
6、查看权限
select * from user_sys_privs;//查看当前用户全部权限
select * from user_tab_privs;//查看所用用户对表的权限
select * from user_sys_privs;//查看当前用户全部权限
select * from user_tab_privs;//查看所用用户对表的权限
7、操做表的用户的表
/*须要在表名前加上用户名,以下*/
select * from zhangsan.tablename
/*须要在表名前加上用户名,以下*/
select * from zhangsan.tablename
8、权限传递
即用户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相似
9、角色 角色即权限的集合,能够把一个角色授予给用户 create role myrole;//建立角色 grant create session to myrole;//将建立session的权限授予myrole grant myrole to zhangsan;//授予zhangsan用户myrole的角色 drop role myrole;删除角色 /*可是有些权限是不能授予给角色的,好比unlimited tablespace和any关键字*/