Oracle 用户治理

Oracle 用户管理
一、创建用户的Profile文件
create profile student limit
<!--
student为资源文件名
-->
FAILED_LOGIN_ATTEMPTS 3
<!--
指定锁定用户的登录失败次数
-->
PASSWORD_LOCK_TIME 5
<!--
指定用户被锁定天数
-->
PASSWORD_LIFE_TIME 30;
<!--
指定口令可用天数
-->
 
二、创建用户
create user 用户名称 identified by 密码 default tablespace 默认表空间 temporary tablespace 临时表空间 profile profile quota integer/unlimited on tablespace;
例:
create user Alice
identified by hanweb // 如果密码是数字,请用双引号括起来
default tablespace account
temporary tablespace temp
profile default
quota 50m on account;
 
--赋权
grant connect, resource to Alice;
 
[*] 查询用户缺省表空间、临时表空间
select username, default_tablespace, temporary_tablespace from dba_users;
 
[*] 查询系统资源文件名:
select * from dba_profiles;
资源文件类似表,一旦创建就会保存在数据库中。
 
select username, profile, default_tablespace, temporary_tablespace from dba_users;
 
create profile common limit
failed_login_attempts 5
idle_time 5;
alter user Alice profile common;
 
三、修改用户
Alter User 用户名
Identified 口令
Default Tablespace tablespace
Temporary Tablespace tablespace
Profile profile
Quota integer/unlimited on tablespace;
1、修改口令字:
Alter user acc01 identified by "12345";
2、修改用户缺省表空间:
Alter user acc01 default tablespace users;
3、修改用户临时表空间
Alter user acc01 temporary tablespace temp_data;
4、强制用户修改口令字:
Alter user acc01 password expire;
5、将用户加锁
Alter user acc01 account lock; // 加锁
Alter user acc01 account unlock; // 解锁
 
四、删除用户
drop user 用户名; //用户没有建任何实体
drop user 用户名 CASCADE; // 将用户及其所建实体全部删除
*1. 当前正连接的用户不得删除。
 
五、监视用户
1、查询用户会话信息:
select username, sid, serial#, machine from v$session;
2、删除用户会话信息:
Alter system kill session 'sid, serial#';
3、查询用户SQL语句:
select user_name, sql_text from v$open_cursor;