日期:2014-05-16  浏览次数:20379 次

如何创建oracle新用户(新schema)
oracle中创建新的user, 也就相应地创建了一个新的schema, 用来区别其他目录的同时, 还保存所有相关user的数据对象以及user的表.

How to create a new user? (create a new db)

首先用system(默认密码为manager)用户登陆连接数据库.

The statement create user creates a user.
In the most simple form, the create user statement is one of the following three:

create user alfredo identified by alfredos_secret;
create user alfredo identified externally;
create user alfredo identified globally as 'external_name';


The first one creates a local user, the second one creates an external user while the last one creates global user.


How to create locked users?

A user can be created locked, that is, the user cannot connect to the database.

SQL> create user alfredo identified by passw0rd account lock;

The user is now created, he can be granted some rights, for example the right to connect to the database:

SQL> grant connect to alfredo;


Now, if the user tries to connect to the database, he will get ORA-28000:

SQL> connect alfredo/passw0rd
ERROR:
ORA-28000: the account is locked


The user can now be unlocked with an alter user statement:

SQL> alter user alfredo account unlock;


Which allows Alfredo to log on to the database now:

SQL> connect alfredo/passw0rd
Connected.


如何赋予用户权限或角色?

可以用grant直接给用户赋予权限, 也可以赋予用户角色, 角色可以看做是权限的集合.
这里我们只讨论角色, 权限可以参考http://www.techonthenet.com/oracle/grant_revoke.php

注意前面grant仅仅赋予了用户connect role, 这个role仅仅是给予用户的一些常见权利,最基本的, 不包括创建表等privileges  
   
   ALTER    SESSION    --修改会话  
   CREATE    CLUSTER    --建立聚簇  
   CREATE    DATABASE    LINK    --建立数据库链接  
   CREATE    SEQUENCE    --建立序列  
   CREATE    SESSION    --建立会话  
   CREATE    SYNONYM    --建立同义词  
   CREATE    VIEW    --建立视图  

如需要可以再赋予resource角色:    --是授予开发人员的  
   
   CREATE    CLUSTER    --建立聚簇  
   CREATE    PROCEDURE    --建立过程  
   CREATE    SEQUENCE    --建立序列  
   CREATE    TABLE    --建表  
   CREATE    TRIGGER    --建立触发器  
   CREATE    TYPE    --建立类型

SQL> grant connect, resource to alfredo;


但是实际查找oracle 10 2.0.1.0 系统时,发现两个role的privileges和上诉有所不同:

用sys登陆到oracle中,执行以下两条语句:

         select * from role_sys_privs WHERE ROLE LIKE 'CONNECT';  --查询connect角色的权限

         select * from role_sys_privs WHERE ROLE LIKE 'RESOURCE';  --查询 resource角色的权限


CONNECT角色:    --是授予终端用户的典型权利,最基本的      
   CREATE    SESSION    --建立会话  
       
RESOURCE角色:    --是授予开发人员的     
 &nb