半夏微凉

半夏微凉

十七、用户及相关权限管理

一、用户管理 
1.创建用户。
create user username identified by password   ##设置用户名和密码
or externally as certificate_DN   ##外部验证,证书验证
or globally as directory_DN    ##全局验证
[default tablespace tapblespace_name]  ##默认表空间
[temporary tablespace tablespace_name|tablespace_group_name]  ##默认临时表空间
[quota size|unlimited on tablespace]   ##限制能使用的表空间大小
[profile profile_name]   ##用户使用的profile文件
[password expire]    ##是否设置用户密码过期
[account lock|unlock]   ##用户是否锁定
例:create user lentim identified 123456 default tablespace LENTIM quota 5M profile pro_test password expire;
2.修改用户。
alter user username identified newpassword
or externally as certificate_DN   ##外部验证,证书验证
or globally as directory_DN    ##全局验证
[default tablespace tapblespace_name]  ##默认表空间
[temporary tablespace tablespace_name|tablespace_group_name]  ##默认临时表空间
[quota size|unlimited on tablespace]   ##限制能使用的表空间大小
[profile profile_name]   ##用户使用的profile文件
[password expire]    ##是否设置用户密码过期
[account {lock|unlock}]   ##用户是否锁定
例:alter user lentim identified lentim default tablespace ORCL;
3.删除用户
drop user username cascade;
二、权限管理
1.赋予系统权限
grant system_privilege    ##系统权限名称
|all privilege to {user identified by password | role |}  
[with admin option]  ##表示当前授权用户也可以给其他用户赋予系统权限
例:grant create session to lentim with admin option;
2.赋予对象权限
grant object_privilege|all
on schema.object  ##用户权限使用的对象,如表对象
to user|role
[with admin option]
[with the grant any object]  ##表示当前用户可以给其他用户赋予对象权限
例:grant delete on t_test to lentim with the grant any object;
3.撤消系统权限
revooke system_privilege from user|role;
4.撤消对象权限
revoke object_privilege|all
on schema_object
from user|role
[cascade contraints]
5.查询用户权限
select * from dba_sys_privs where grantee='LENTIM';
select * from dba_tab_privs where grantee='LENTIM';
三、角色管理
1.创建角色
create role role_name
[not identified|identified by [password]   ##无需验证|密码验证
identified by exeternally  ##外部验证
identified by globally]   ##全局验证
例:create role test_role not identified; 
2.赋予角色权限
grant system_privilege | all privilege
to role
[with admin option]
例:grant create session to test_role;
3.设置角色
grant role_name to user;
4.控制角色是否有效
set role role_name;
set role all;
set role all except role;
set role none;
5.修改角色
alter role role_name ....
6.删除角色
drop role rolename;
四、概要文件profile
1.概要文件新增
create profile profile_name
limit
{resource_parameters|password_parameters}  ##资源参数|口令参数
//resource_parameters,这些参数主要有
CPU_PER_SESSITION 允许一个会话占用的cpu总量
CPU_PER_CALL 允许一个调用占用cpu的最大值
CONNECT_TIME 允许一个持续的会话的时间最大值
//password_parameters 常用的参数有
PASSWORD_LIFE_TIME 指多少天后口令失效
PASSWORD_REUSE_TIME 指密码保留的时间
PASSWORD_GRACE_TIME 指密码失效后锁定
例:create profile pro_test limit password_life_time 30;
2.修改profile
alter profile profile_name limit {resource_parameters|password_parameters};
例:alter profile pro_test limit password_life_time 90;
3.删除profile
drop profile profile_name [cascade];
4.查询profile
select distinct profile from dba_profiles;


评论回复


·