创建用户
在oracle中必须要使用用户登录数据库,通过密码完成用户身份认证,一旦登录,用户就可以访问他拥有的数据库对象。
创建新的用户
创建信息用户必须使用DBA权限用户
-
使用DBA用户登录数据库
[root@oracle admin]# sqlplus
SQL*Plus: Release 11.2.0.4.0 Production on 星期四 4月 9 02:17:34 2020
Copyright (c) 1982, 2013, Oracle. All rights reserved.
请输入用户名: sys as sysdba
输入口令:
连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
-
创建数据库用户
下面操作中每一行的含义:
- create user test identified by test:创建用户test,设置用户密码为test
- default tablespace users:设置默认的表空间为USERS表空间,该控件用于存储用户数据
- temporary tablespace temp:创建临时表空间,该表空间为用户可以用来排序等操作的数据空间
- quota 10m on users:为users表空间分配10M
- password expire:说明用户登录时密码立即失效,oracle会提示重新设置密码
SQL> create user test identified by test
2 default tablespace users
3 temporary tablespace temp
4 quota 10m on users
5 password expire;
用户已创建。
由于创建用户时,没有赋予该用户CREATE SESSION 权利,所以虽然更改了用户密码,还是无法建立数据库的会话连接,需要向用户授权。
向用户授予CREATE SESSION权限
SQL> grant create session,resource to test;
授权成功。
SQL> conn test/test
ERROR:
ORA-28001: the password has expired
更改 test 的口令
新口令:
重新键入新口令:
口令已更改
已连接。
SQL>
删除用户并查看
SQL> drop user test1;
用户已删除。
SQL> select username,user_id,password from dba_users;
USERNAME USER_ID PASSWORD
------------------------------------------------------------------------------------------ ---------- ------------------------------------------------------------------------------------------
MGMT_VIEW 73
SYS 0
SYSTEM 5
DBSNMP 30
SYSMAN 71
SCOTT 83
TT 90
TEST 93
OUTLN 9
FLOWS_FILES 74
MDSYS 57
USERNAME USER_ID PASSWORD
------------------------------------------------------------------------------------------ ---------- ------------------------------------------------------------------------------------------
ORDSYS 53
EXFSYS 42
WMSYS 32
APPQOSSYS 31
APEX_030200 77
OWBSYS_AUDIT 79
ORDDATA 54
CTXSYS 43
ANONYMOUS 46
XDB 45
ORDPLUGINS 55
USERNAME USER_ID PASSWORD
------------------------------------------------------------------------------------------ ---------- ------------------------------------------------------------------------------------------
OWBSYS 78
SI_INFORMTN_SCHEMA 56
OLAPSYS 60
ORACLE_OCM 21
XS$NULL 2147483638
BI 89
PM 88
MDDATA 64
IX 86
SH 87
DIP 14
USERNAME USER_ID PASSWORD
------------------------------------------------------------------------------------------ ---------- ------------------------------------------------------------------------------------------
OE 85
APEX_PUBLIC_USER 75
HR 84
SPATIAL_CSW_ADMIN_USR 69
SPATIAL_WFS_ADMIN_USR 66
已选择38行。
解锁用户
SQL> create user test1 identified by 123456 default tablespace users temporary tablespace temp quota 10m on users password expire account lock;
用户已创建。
SQL> conn test1/123456
ERROR:
ORA-28000: the account is locked
警告: 您不再连接到 ORACLE。
SQL> conn sys as sysdba
输入口令:
已连接。
SQL> alter user test1 identified by test account unlock;
用户已更改。
SQL> conn sys as sysdba
输入口令:
已连接。
SQL> grante create session to test1;
SP2-0734: 未知的命令开头 "grante cre..." - 忽略了剩余的行。
SQL> grant create session to test1;
授权成功。
SQL> conn test1/test
已连接。
SQL>
用户和数据库模式
模式与用户对应,当用户创建时,也对应地创建了一个模式,二者是一对一的关系,名字相同。
模式的命名时数据库对象的集合,用户拥有数据库模式,并且用户名和模式经常互换使用。
模式对象:
- 表
- 触发器
- 约束
- 索引
- 视图
- 序列号
- 存储过程
- 同义词
- 用户定义的数据类型
- 函数
- 软件包
查看用户scott拥有的模式对象
我们可以使用user_objects来查看用户所拥有的模式对象
SQL> conn scott/tiger;
已连接。
SQL> select distinct object_name from user_objects;
OBJECT_NAME
--------------------------------
DEPT
PK_DEPT
EMP
BONUS
PK_EMP
SALGRADE
用户管理中的重要文件----概要文件
在创建用户之后就需要给该用户分配各种资源,oracle数据库提供了概要文件来避免资源问题。