Oracle SQL 基本操作之 用户权限管理方法
最近把有关用户操作和权限管理的东西整理了一下,虽然不少博客都有过类似的整理,但是自己发现他们的内容或多或少都有些错误。于是,本人亲自对每条语句进行验证后,并对其做了自己的讲解和分析,撰写本篇博客。或仍有错误之处,望各位指出,谢谢! 闲话少说,开始进入正题!一、系统用户sys;//系统管理员,拥有最高权限 system;//本地管理员,次高权限 scott;//普通用户,密码默认为tiger,默认未解锁 二、登陆 sqlplus / as sysdba;//登陆sys帐户 sqlplus sys as sysdba;//登陆sys账户,方法二sqlplus scott/tiger;//登陆普通用户scott 三、管理用户 create user starive;//在管理员帐户下,创建用户starivealert user scott identified by tiger;//修改密码 四,授予权限 1、默认的普通用户scott默认未解锁,不能进行那个使用,新建的用户也没有任何权限,必须授予权限 ### 以下都需要管理员授权 ###grant create session to starive;//授予starive用户创建session的权限,即登陆权限 ### tablespace ###grant unlimited tablespace to starive;//授予starive用户使用表空间的权限 grant create tablespace to starive;//授予 starive 创建表空间的权限grant drop tablespace to starive;//授予starive用户使用表空间的权限 grant alter tablespace to starive;//授予 starive 修改表空间的权限grant manage tablespace to starive;//授予 starive 管理表空间的权限### table ###grant create any table to starive;//授予创建表的权限 grant drop any table to starive;//授予删除表的权限 grant insert any table to starive;//插入表的权限 grant update any table to starive;//修改表的权限 grant select any table to starive;//查询表的权限 grant all privileges to public; //授予所有权限(all)给所有用户(public) !!!小心使 用,用了后它跟system权限一样grant all privileges to starive; //授予所有权限(all)给用户starive !!!小心使用2、oralce对权限管理比较严谨,普通用户之间也是默认不能互相访问的,需要互相授权 grant select on tablename to starive;//授予starive用户查看指定表的权限 grant drop on tablename to starive;//授予删除表的权限 grant insert on tablename to starive;//授予插入的权限 grant update on tablename to starive;//授予修改表的权限 grant insert(id) on tablename to starive; grant update(id) on tablename to starive;//授予对指定表特定字段的插入和修改权限,注意,只能是insert和update grant alert all table to starive;//授予starive用户alert任意表的权限 五、撤销权限 revoke select on tablename from starive;//授予starive用户查看指定表的权限 revoke drop on tablename from starive;//授予删除表的权限 revoke insert on tablename from starive;//授予插入的权限 revoke update on tablename from starive;//授予修改表的权限 revoke insert(id) on tablename from starive; revoke update(id) on tablename from starive;//授予对指定表特定字段的插入和修改权限,注意,只能是insert和update revoke alert all table from starive;//授予starive用户alert任意表的权限 ***revoke和grant语法基本一致,只是前者是to<用户>,而后者是 from<用户>六、查看权限 select * from user_sys_privs;//查看当前用户所有权限 select * from user_tab_privs;//查看所用用户对表的权限 七、操作表的用户的表 /*需要在表名前加上用户名,如下例*/ select * from starive.tablename 八、权限传递 即用户A将权限授予B,B可以将操作的权限再授予C,命令如下: grant alert table on tablename to starive with admin option;//关键字 with admin option grant alert table on tablename to starive with grant option;//关键字 with grant option效果和admin类似 九、角色 角色即权限的集合,可以把一个角色授予给用户 create role myrole;//创建角色 grant create session to myrole;//将创建session的权限授予myrole grant myrole to starive;//授予starive用户myrole的角色 drop role myrole;删除角色 /*但是有些权限是不能授予给角色的,比如unlimited tablespace和any关键字*/十 命令SQL> select distinct PRIVILEGE from DBA_SYS_PRIVS where privilege like '%TABLE%';SQL> select distinct PRIVILEGE from DBA_SYS_PRIVS where privilege like '%TABLE%';题记: 有些权限要小心使用,因为授予权限过大,会很危险。一不小心,系统就崩了....