Oracle 用户及角色 介绍

. 用户管理

1.1 建立用户(数据库验证)

     CREATE  USER   DAVE  IDENTIFIED  BY   pwd

     DEFAULT TABLESPACE  users

     TEMPORARY   TABLESPACE  temp

     QUOTA  5m  ON  users;

 

1.2 修改用户

ALTER USER DAVE QUOTA 0 ON SYSTEM;

 

1.3 删除用户

DROP USER DAVE;

DROP USER DAVE CASCADE;

 

1.4 显示用户信息

SELECT * FROM DBA_USERS

SELECT * FROM DBA_TS_QUOTAS

 

.系统权限

系统权限

作用

CREATE SESSION

连接到数据库

CREATE TABLE

建表

CREATE TABLESPACE

建立表空间

CREATE VIEW

建立视图

CREATE SEQUENCE

建立序列

CREATE USER

建立用户

 

系统权限是指执行特定类型SQL命令的权利,用于控制用户可以执行的一个或一类数据库操作。(新建用户没有任何权限)

 

2.1 授予系统权限

GRANT CREATE SESSION,CREATE TABLE TO DAVE;

GRANT CREATE SESSION TO DAVE WITH ADMIN OPTION;

 

选项:ADMIN OPTION 使该用户具有转授系统权限的权限。

 

2.2 显示系统权限

 

查看所有系统权限:

Select * from system_privilege_map;

显示用户所具有的系统权限:

Select * from dba_sys_privs;

显示当前用户所具有的系统权限:

Select * from user_sys_privs;

显示当前会话所具有的系统权限:

Select * from session_privs;

 

2.3 收回系统权限

REVOKE CREATE TABLE FROM DAVE;

REVOKE CREATE SESSION FROM DAVE;

 

 

.角色:

角色是一组相关权限的命名集合,使用角色最主要的目的是简化权限管理。

 

3.1 预定义角色。

CONNECT自动建立,包含以下权限:ALTER SESSIONCREATE CLUSTERCREATE DATABASELINKCREATE SEQUENCECREATE SESSIONCREATE SYNONYMCREATE TABLECREATEVIEW

RESOURCE自动建立,包含以下权限:CREATE CLUSTERCREATE PROCEDURECREATE SEQUENCECREATE TABLECREATE TRIGGR

 

3.2 显示角色信息,

§ROLE_SYS_PRIVS

§ROLE_TAB_PRIVS

§ROLE_ROLE_PRIVS

§SESSION_ROLES

§USER_ROLE_PRIVS

§DBA_ROLES

 

. Oracle用户角色

每个Oracle用户都有一个名字和口令,并拥有一些由其创建的表、视图和其他资源。

Oracle角色(role就是一组权限(privilege(或者是每个用户根据其状态和条件所需的访问类型)。用户可以给角色授予或赋予指定的权限,然后将角色赋给相应的用户。一个用户也可以直接给其他用户授权。

数据库系统权限(Database System Privilege)允许用户执行特定的命令集。例如,CREATE TABLE权限允许用户创建表,GRANT ANY PRIVILEGE权限允许用户授予任何系统权限。

数据库对象权限(Database Object Privilege)使得用户能够对各个对象进行某些操作。例如DELETE权限允许用户删除表或视图的行,SELECT权限允许用户通过select从表、视图、序列(sequences)或快照 snapshots)中查询信息。

 

4.1 创建用户

Oracle内部有两个建好的用户:SYSTEMSYS。用户可直接登录到SYSTEM用户以创建其他用户,因为SYSTEM具有创建别的用户的权限。在安装Oracle时,用户或系统管理员首先可以为自己建立一个用户。例如:

create user user01 identified by u01;

该命令还可以用来设置其他权限。

改变一个口令,可以使用alter user命令:

alter user user01 identified by usr01;

 现在user01的口令已由“u01”改为“usr01”

 

除了alter user命令以外,用户还可以使用password命令。如果使用password命令,用户输入的新口令将不在屏幕上显示。dba特权的用户可以通过password命令改变任何其他用户的口令;其他用户只能改变自己的口令。

 

当用户输入password命令时,系统将提示用户输入旧口令和新口令,如下所示:

password

    Changing password for user01

    Old password:

    New password:

    Retype new password:

    当成功地修改了口令时,用户会得到如下的反馈:

Password changed

 

4.2 删除用户

    删除用户,可以使用drop user命令,如下所示:

drop user user01;

如果用户拥有对象,则不能直接删除,否则将返回一个错误值。指定关键字CASCADE,可删除用户所有的对象,然后再删除用户。

下面的例子用来删除用户与其对象:

drop user user01 CASCADE;

 

4.3 3种标准角色

Oracle为了兼容以前的版本,提供了三种标准的角色(role):CONNECTRESOURCEDBA

 

4.3.1. CONNECT Role(连接角色)

临时用户,特别是那些不需要建表的用户,通常只赋予他们CONNECT roleCONNECT是使用Oracle的简单权限,这种权限只有在对其他用户的表有访问权时,包括selectinsertupdatedelete等,才会变得有意义。拥有CONNECT role的用户还能够创建表、视图、序列(sequence)、簇(cluster)、同义词(synonym )、会话(session)和与其他数据库的链(link)。

 

4.3.2. RESOURCE Role(资源角色)

更可靠和正式的数据库用户可以授予RESOURCE roleRESOURCE提供给用户另外的权限以创建他们自己的表、序列、过程(procedure)、触发器(trigger)、索引(index)和簇(cluster)。

 

4.3.3. DBA Role(数据库管理员角色)

DBA role拥有所有的系统权限----包括无限制的空间限额和给其他用户授予各种权限的能力。SYSTEMDBA用户拥有。

 

一些DBA经常使用的典型权限。

    1. grant(授权)命令

                      grant connect, resource to user01;

2. revoke(撤消)权限

    revoke connect, resource from user01;

 

一个具有DBA角色的用户可以撤消任何别的用户甚至别的DBACONNECTRESOURCE DBA的其他权限。当然,这样是很危险的,因此,除非真正需要,DBA权限不应随便授予那些不是很重要的一般用户。

撤消一个用户的所有权限,并不意味着从Oracle中删除了这个用户,也不会破坏用户创建的任何表;只是简单禁止其对这些表的访问。其他要访问这些表的用户可以象以前那样地访问这些表。

 

五、创建角色

   除了前面讲到的三种系统角色----CONNECTRESOURCEDBA,用户还可以在Oracle创建自己的role用户创建的role可以由表或系统权限或两者的组合构成。为了创建role用户必须具有CREATE ROLE系统权限

 

5.1 创建role

create role STUDENT;

这条命令创建了一个名为STUDENTrole

 

5.2 role 授权

一旦创建了一个role,用户就可以给他授权。给role授权的grant命令的语法与对对用户的语法相同。在给role授权时,在grant命令的to子句中要使用role的名称,如下所示:

grant select on CLASS to STUDENT;

现在,拥有STUDENT角色的所有用户都具有对CLASS表的select权限。

 

5.3 删除角色

   要删除角色,可以使用drop role命令,如下所示:

drop role STUDENT;

指定的role连同与之相关的权限将从数据库中全部删除。

 

. oracle sys system 用户的区别

      sysOracle数据库中权限最高的帐号,具有create database的权限,
system没有这个权限,sys的角色是sysdbasystem的角色是sysoper

 

其余就是他们两个用户共有的权限了:
startup/shutdown/dba
两个用户都是可以管理的。平时用system来管理数据库就可以了。这个用户的权限对于普通的数据库管理来说已经足够权限了。

 

. 查看权限和角色

ORACLE中数据字典视图分为3大类, 用前缀区别,分别为:USERALL DBA,许多数据字典视图包含相似的信息。

 

USER_*: 有关用户所拥有的对象信息,即用户自己创建的对象信息

ALL_* 有关用户可以访问的对象的信息,即用户自己创建的对象的信息加上其他用户创建的对象但该用户有权访问的信息

DBA_*有关整个数据库中对象的信息

(这里的*可以为TABLES INDEXES OBJECTS USERS等)。

 

比如:只知道scott用户的密码,需要查看一下scott的一些信息


7.1
、查scott用户的创建时间、用户状态、使用的默认表空间、临时表空间等信息

SQL> conn scott/admin

已连接。

SQL>select * from user_users;

另:select * from all_users;(scott用户可以访问其他数据库用户对信息的用户名)
另:select * from all_users;(所有数据库的用户信息,各用户的密码、状态、默认表空间、临时表空间等)

 

7.2、查看scott用户自己拥有什么角色

SQL> select * from user_role_privs;

USERNAME  GRANTED_ROLE  ADM  DEF  OS_

------------------------------ ------------------------------ --- --- ---

SCOTT        CONNECT      NO     YES      NO

SCOTT        RESOURCE    NO      YES     NO

注:ADM”表示这个用户是否可以把该具有的角色赋予给其他的用户

另:没有all_role_privs这个视图
另:select * from dba_role_privs(所有数据库用户具有哪些角色,这个视图只有dba角色的权限才可以查询

 

7.3、查看scott用户自己具有什么的权限

SQL> select * from session_privs;

 

7.4、查看scott用户具有什么的系统权限呢

SQL>select * from user_sys_privs;

另:没有all_sys_privs视图
另:select * from dba_sys_privs;(所有数据库用户、角色所用于的系统权限)

 

7.5、查看scott用户中,都哪些用户把对象授予给scott用户呢(读取其他用户对象的权限)

SQL>select * from user_tab_privs;

另:select * from all_tab_privs;   select * from dba_tab_privs; 

 

7.6、查看scott用户中拥有的resource角色都具有什么权限呢

SQL> select * from role_sys_privs where role='RESOURCE';

ROLE     PRIVILEGE   ADM

------------------------------ -------------------------------

RESOURCE CREATE SEQUENCE NO

RESOURCE CREATE TRIGGER NO

RESOURCE CREATE CLUSTER NO

RESOURCE CREATE PROCEDURE NO

RESOURCE CREATE TYPE NO

RESOURCE CREATE OPERATOR NO

RESOURCE CREATE TABLE NO

RESOURCE CREATE INDEXTYPE NO

已选择8行。

 

7.7scott用户自己拥有多少的表

SQL>select * from user_tables;

另:select * from all_tables; 其他用户所拥有的表
另:select * from dba_tables;数据库中所有用户的表

 

7.8、查看scott用户已经使用多大的空间,允许使用的最大空间是多少

SQL> select tablespace_name,bytes,max_bytes from user_ts_quotas;

另:select * from dba_ts_quotas;(所有的数据库用户在每个表空间已使用的空间,最大空间)

 

7.9、把自己的表赋予给其他用户

SQL>grant select on emp to mzl;

查看都把哪些表什么权限赋予了其他用户

SQL>select * from user_tab_privs_made

 

7.10、把表的某一列操作权限赋予给其他用户

SQL>grant update(job) on emp to mzl;

注:查看数据库中所有的角色select * form. dba_roles;

 

7.11sys授予scott用户dba角色

SQL> conn /as sysdba

已连接。

SQL> grant dba to scott;

授权成功。

另:如果这样

SQL> grant dba to scott with admin option;

授权成功。

scott用户就可以把dba的权限授予给其他的用户了。

7.12 sys回收scott用户的dba角色

SQL> revoke dba from scott;

撤销成功。

 

 

 

八.Oracle 用户及作用介绍


 

http://docs.oracle.com/cd/B28359_01/server.111/b28337/tdpsg_user_accounts.htm

 

Oracle 官方文档对Oracle 的用户分成了三类:

(1)     PredefinedAdministrative Accounts

(2)     PredefinedNon-Administrative User Accounts

(3)     PredefinedSample Schema User Accounts

 

 

8.1 Predefined Administrative Accounts

A default OracleDatabase installation provides a set of predefined administrative accounts. These are accounts that have specialprivileges required to administer areas of the database, such as the CREATEANY TABLE or ALTER SESSION privilege, or EXECUTE privilegeson packages owned by the SYSschema. The default tablespace foradministrative accounts is either SYSTEM or SYSAUX.

 

Table 3-1 Predefined Oracle DatabaseAdministrative User Accounts

User Account

Description

Status After Installation

ANONYMOUS

Account that allows HTTP access to Oracle XML DB. It is used in place of theAPEX_PUBLIC_USER account when the Embedded PL/SQL Gateway (EPG) is installed in the database.

EPG is a Web server that can be used with Oracle Database. It provides the necessary infrastructure to create dynamic applications.

Expired and locked

CTXSYS

The account used to administer Oracle Text. Oracle Text enables you to build text query applications and document classification applications. It provides indexing, word and theme searching, and viewing capabilities for text.

See Oracle Text Application Developer's Guide.

Expired and locked

DBSNMP

The account used by the Management Agent component of Oracle Enterprise Manager to monitor and manage the database.

See Oracle Enterprise Manager Grid Control Installation and Basic Configuration.

Open

Password is created at installation or database creation time.

EXFSYS

The account used internally to access the EXFSYS schema, which is associated with the Rules Manager and Expression Filter feature. This feature enables you to build complex PL/SQL rules and expressions. The EXFSYS schema contains the Rules Manager and Expression Filter DDL, DML, and associated metadata.

See Oracle Database Rules Manager and Expression Filter Developer's Guide.

Expired and locked

LBACSYS

The account used to administer Oracle Label Security (OLS). It is created only when you install the Label Security custom option.

See "Enforcing Row-Level Security with Oracle Label Security" and Oracle Label Security Administrator's Guide.

Expired and locked

MDSYS

The Oracle Spatial and Oracle Multimedia Locator administrator account.

See Oracle Spatial Developer's Guide.

Expired and locked

MGMT_VIEW

An account used by Oracle Enterprise Manager Database Control.

Open

Password is randomly generated at installation or database creation time. Users do not need to know this password.

OLAPSYS

The account that owns the OLAP Catalog (CWMLite). This account has been deprecated, but is retained for backward compatibility.

Expired and locked

OWBSYS

The account for administrating the Oracle Warehouse Builder repository.

Access this account during the installation process to define the base language of the repository and to define Warehouse Builder workspaces and users. A data warehouse is a relational or multidimensional database that is designed for query and analysis.

See Oracle Warehouse Builder Installation and Administration Guide.

Expired and locked

ORDPLUGINS

The Oracle Multimedia user. Plug-ins supplied by Oracle and third-party, format plug-ins are installed in this schema.

Oracle Multimedia enables Oracle Database to store, manage, and retrieve images, audio, video, DICOM format medical images and other objects, or other heterogeneous media data integrated with other enterprise information.

See Oracle Multimedia User's Guide and Oracle Multimedia Reference.

Expired and locked

ORDSYS

The Oracle Multimedia administrator account.

See Oracle Multimedia User's GuideOracle Multimedia Reference, and Oracle Multimedia DICOM Developer's Guide.

Expired and locked

OUTLN

The account that supports plan stability. Plan stability prevents certain database environment changes from affecting the performance characteristics of applications by preserving execution plans in stored outlines. OUTLN acts as a role to centrally manage metadata associated with stored outlines.

See Oracle Database Performance Tuning Guide.

Expired and locked

SI_INFORMTN_SCHEMA

The account that stores the information views for the SQL/MM Still Image Standard.

See Oracle Multimedia User's Guide and Oracle Multimedia Reference.

Expired and locked

SYS

An account used to perform database administration tasks.

See Oracle Database 2 Day DBA.

Open

Password is created at installation or database creation time.

SYSMAN

The account used to perform Oracle Enterprise Manager database administration tasks. The SYS and SYSTEM accounts can also perform these tasks.

See Oracle Enterprise Manager Grid Control Installation and Basic Configuration.

Open

Password is created at installation or database creation time.

SYSTEM

A default generic database administrator account for Oracle databases.

For production systems, Oracle recommends creating individual database administrator accounts and not using the generic SYSTEM account for database administration operations.

See Oracle Database 2 Day DBA.

Open

Password is created at installation or database creation time.

TSMSYS

An account used for transparent session migration (TSM).

Expired and locked

WK_TEST

The instance administrator for the default instance, WK_INST. After you unlock this account and assign this user a password, then you must also update the cached schema password using the administration tool Edit Instance Page.

Ultra Search provides uniform search-and-location capabilities over multiple repositories, such as Oracle databases, other ODBC compliant databases, IMAP mail servers, HTML documents managed by a Web server, files on disk, and more.

See Oracle Ultra Search Administrator's Guide.

Expired and locked

WKSYS

An Ultra Search database super-user. WKSYS can grant super-user privileges to other users, such as WK_TEST. All Oracle Ultra Search database objects are installed in the WKSYS schema.

See Oracle Ultra Search Administrator's Guide.

Expired and locked

WKPROXY

An administrative account of Oracle9i Application Server Ultra Search.

See Oracle Ultra Search Administrator's Guide.

Expired and locked

WMSYS

The account used to store the metadata information for Oracle Workspace Manager.

See Oracle Database Workspace Manager Developer's Guide.

Expired and locked

XDB

The account used for storing Oracle XML DB data and metadata.

Oracle XML DB provides high-performance XML storage and retrieval for Oracle Database data.

See Oracle XML DB Developer's Guide.

Expired and locked

 

 

8.2 PredefinedNon-Administrative User Accounts

Non-administrativeuser accounts only have the minimum privileges needed to perform their jobs.Their default tablespace is USERS.

 

Table 3-2 PredefinedOracle Database Non-Administrative User Accounts

User Account

Description

Status After Installation

APEX_PUBLIC_USER

The Oracle Database Application Express account. Use this account to specify the Oracle schema used to connect to the database through the database access descriptor (DAD).

Oracle Application Express is a rapid, Web application development tool for Oracle Database.

See Oracle Database Application Express User's Guide.

Expired and locked

DIP

The Oracle Directory Integration and Provisioning (DIP) account that is installed with Oracle Label Security. This profile is created automatically as part of the installation process for Oracle Internet Directory-enabled Oracle Label Security.

See Oracle Label Security Administrator's Guide.

Expired and locked

FLOWS_30000

The account that owns most of the database objects created during the installation of Oracle Database Application Express. These objects include tables, views, triggers, indexes, packages, and so on.

See Oracle Database Application Express User's Guide.

Expired and locked

FLOWS_FILES

The account that owns the database objects created during the installation of Oracle Database Application Express related to modplsql document conveyance, for example, file uploads and downloads. These objects include tables, views, triggers, indexes, packages, and so on.

See Oracle Database Application Express User's Guide.

Expired and locked

MDDATA

The schema used by Oracle Spatial for storing Geocoder and router data.

Oracle Spatial provides a SQL schema and functions that enable you to store, retrieve, update, and query collections of spatial features in an Oracle database.

See Oracle Spatial Developer's Guide.

Expired and locked

ORACLE_OCM

The account used with Oracle Configuration Manager. This feature enables you to associate the configuration information for the current Oracle Database instance with OracleMetaLink. Then when you log a service request, it is associated with the database instance configuration information.

See Oracle Database Installation Guide for your platform.

Expired and locked

SPATIAL_CSW_ADMIN_USR

The Catalog Services for the Web (CSW) account. It is used by Oracle Spatial CSW Cache Manager to load all record-type metadata and record instances from the database into the main memory for the record types that are cached.

See Oracle Spatial Developer's Guide.

Expired and locked

SPATIAL_WFS_ADMIN_USR

The Web Feature Service (WFS) account. It is used by Oracle Spatial WFS Cache Manager to load all feature type metadata and feature instances from the database into main memory for the feature types that are cached.

See Oracle Spatial Developer's Guide.

Expired and locked

XS$NULL

An internal account that represents the absence of a user in a session. Because XS$NULL is not a user, this account can only be accessed by the Oracle Database instance. XS$NULL has no privileges and no one can authenticate as XS$NULL, nor can authentication credentials ever be assigned to XS$NULL.

Expired and locked

 

8.3 PredefinedSample Schema User Accounts

 

If you install the sample schemas, which you must doto complete the examples in this guide, Oracle Database creates a set of sampleuser accounts. The sample schema user accounts are all non-administrativeaccounts, and their tablespace is USERS.

 

Table 3-3 DefaultSample Schema User Accounts

User Account

Description

Status After Installation

BI

The account that owns the BI (Business Intelligence) schema included in the Oracle Sample Schemas.

See also Oracle Warehouse Builder User's Guide.

Expired and locked

HR

The account used to manage the HR (Human Resources) schema. This schema stores information about the employees and the facilities of the company.

Expired and locked

OE

The account used to manage the OE (Order Entry) schema. This schema stores product inventories and sales of the company's products through various channels.

Expired and locked

PM

The account used to manage the PM (Product Media) schema. This schema contains descriptions and detailed information about each product sold by the company.

Expired and locked

IX

The account used to manage the IX (Information Exchange) schema. This schema manages shipping through business-to-business (B2B) applications.

Expired and locked

SH

The account used to manage the SH (Sales) schema. This schema stores business statistics to facilitate business decisions.

Expired and locked

 


 



-------------------------------------------------------------------------------------------------------

QQ:492913789

Email:[email protected]

Blog: http://www.cndba.cn/dave


DBA1 群:62697716(满);   DBA2 群:62697977(满)   DBA3 群:62697850(满)  
DBA 超级群:63306533(满);  DBA4 群: 83829929  DBA5群: 142216823   
聊天 群:40132017   聊天2群:69087192
--加群需要在备注说明Oracle表空间和数据文件的关系,否则拒绝申请

 

你可能感兴趣的:(Oracle,Basic,Knowledge,oracle基础知识大全)