用户管理

2014-11-08  本文已影响39人  wswenyue

创建用户

  1. 创建一个用户OU1,口令为:OU1,默认表空间为USERS,该表空间的配额为10M,初始状态为锁定。
SQL> create user ou1 identified by ou1
  2  default tablespace users quota 10M on users account lock;
  1. 创建一个用户OU2,口令为:OU2,默认表空间为USERS,该表空间的配额为10M,口令设置为过期状态,即首次连接数据库时需要修改口令,概要文件为example_profile(假设该概要文件已经创建,下面又讲到概要文件,可以把example_profile替换一下就好)。
SQL> create user ou2 identified by ou2
  2  default tablespace users quota 10M on users 
  3  profile example_profile password expire;

用户权限

SQL> connect ou3/ou3
ERROR:
ORA-12560: TNS:protocol adapter error
Warning: You are no longer connected to ORACLE.

提示没有连接权限,无法连接。
下面我们给予其连接权限

SQL> grant create session to ou3;
Grant succeeded.

连接成功

SQL> connect ou3/ou3@wy-data
Connected.

到这里OU3用户只有连接的权限,没有创建表的权限,创建表会提示错误:

SQL> create table t
  2  (
  3   x number,
  4  y varchar2(10)
  5  )
  6   /
create table t
*
ERROR at line 1:
ORA-01031: insufficient privileges

这里我们赋予其创建表的权限。

SQL> grant create table to ou3;
Grant succeeded.

现在就可以创建表了

概要文件

SQL> create profile miser
  2  limit
  3  connect_time 200
  4  idle_time 60
  5  sessions_per_user 2
  6  failed_login_attempts 3
  7  /

注:我们创建的概要文件为miser(中文翻译为“守财奴”,我时常看一些大师级写的书,他们对名字的取法很讲究,我这里也用一下),connect_time指出数据库允许最大连接120秒,idle_time指出如果用户空闲的时间超出60秒,那么用户将退出;
sessions_per_user指出限制用户只能有两个会话;failed_login_attempts指出如果用户登录三次没有成功,那么,该用户将被锁住。概要文件可以在用户创建时指定,也可以在用户创建后指定。
创建时指定上面又讲到,现在我们讲讲用户创建后指定

SQL> alter user ou1
  2  profile miser
  3  /

上一篇 下一篇

猜你喜欢

热点阅读