Oracle中管理用户

SQL> --创建一个用户
SQL> create user itcast identified by password;
create user itcast identified by password
            *
第 1 行出现错误:
ORA-01920: 用户名 'ITCAST' 与另外一个用户名或角色名发生冲突


SQL> create user abc identified by password;

用户已创建。

SQL> --为abc赋予登录权限,1. connect 2. create session
SQL> grant create session to abc;

授权成功。

SQL> --给用户加锁
SQL> alter user abc account lock;

用户已更改。

SQL> --给用户解锁
SQL> alter user abc account unlock;

用户已更改。

SQL> --修改密码
SQL> alter user abc identified by password;

用户已更改。

SQL> --admin option授权的级联
SQL> show user;
USER 为 "SYS"
SQL> --创建两个用户 jeff emi
SQL> create user jeff identified by password;

用户已创建。

SQL> create user emi identified by password;

用户已创建。

SQL> --授予登录的权限
SQL> grant create session to jeff with admin option;

授权成功。

SQL> --切换到jeff下
SQL> conn jeff/password
已连接。
SQL> show user
USER 为 "JEFF"
SQL> --jeff把create session赋予emi
SQL> grant create session to emi;

授权成功。

SQL> host cls

SQL> --回到管理员下
SQL> --撤销jeff登录的权限
SQL> revoke create session from jeff;

撤销成功。

SQL> grant connect,resource to jeff;
grant connect,resource to jeff
*
第 1 行出现错误:
ORA-01031: 权限不足


SQL> show user;
USER 为 "JEFF"
SQL> conn / as sysdba
已连接。
SQL> grant connect,resource to jeff;

授权成功。

SQL> grant connect,resource to emi;

授权成功。

SQL> host cls

SQL> --切换到scott下,并且授予jeff查询emp的权限
SQL> conn scott/tiger
已连接。
SQL> grant select on emp to jeff with grant option;

授权成功。

SQL> --回到jeff下
SQL> conn jeff/password
已连接。
SQL> select ename from scott.emp;

ENAME                                                                          
----------                                                                     
SMITH                                                                          
ALLEN                                                                          
WARD                                                                           
JONES                                                                          
MARTIN                                                                         
BLAKE                                                                          
CLARK                                                                          
SCOTT                                                                          
KING                                                                           
TURNER                                                                         
ADAMS                                                                          

ENAME                                                                          
----------                                                                     
JAMES                                                                          
FORD                                                                           
MILLER                                                                         

已选择14行。

SQL> host cls

SQL> show user;
USER 为 "JEFF"
SQL> --jeff又把scott.emp的select授予emi
SQL> grant select on scott.emp to emi;

授权成功。

SQL> --切换到emi下
SQL> conn emi/password
已连接。
SQL> select ename from scott/emp;
select ename from scott/emp
                       *
第 1 行出现错误:
ORA-00933: SQL 命令未正确结束


SQL> select ename from scott.emp;

ENAME                                                                          
----------                                                                     
SMITH                                                                          
ALLEN                                                                          
WARD                                                                           
JONES                                                                          
MARTIN                                                                         
BLAKE                                                                          
CLARK                                                                          
SCOTT                                                                          
KING                                                                           
TURNER                                                                         
ADAMS                                                                          

ENAME                                                                          
----------                                                                     
JAMES                                                                          
FORD                                                                           
MILLER                                                                         

已选择14行。

SQL> host cls

SQL> --回到scott下,并且撤销jeff查询emp表的权限
SQL> revoke select on emp from jeff;
revoke select on emp from jeff
                 *
第 1 行出现错误:
ORA-00942: 表或视图不存在


SQL> show user;
USER 为 "EMI"
SQL> conn scott/tiger
已连接。
SQL> revoke select on emp from jeff;

撤销成功。

SQL> conn jeff/passowrd
ERROR:
ORA-01017: invalid username/password; logon denied


警告: 您不再连接到 ORACLE。
SQL> exit
SQL> select * from scott.emp;
select * from scott.emp
                    *
第 1 行出现错误:
ORA-00942: 表或视图不存在


SQL> conn emi/password
已连接。
SQL> select * from scott.emp;
select * from scott.emp
                    *
第 1 行出现错误:
ORA-00942: 表或视图不存在


SQL> host cls

SQL> show user;
USER 为 "EMI"
SQL> conn sys/password
ERROR:
ORA-28009: connection as SYS should be as SYSDBA or SYSOPER


警告: 您不再连接到 ORACLE。
SQL> exit
SQL> /*
SQL>
SQL> 当创建完用户后,一般立即授予角色connect resource
SQL> */
SQL> --创建一个role
SQL> show user
USER 为 "SYS"
SQL> create role myrole;
create role myrole
            *
第 1 行出现错误:
ORA-01921: 角色名 'MYROLE' 与另一个用户名或角色名发生冲突


SQL> create role myrole123;
create role myrole123
            *
第 1 行出现错误:
ORA-01921: 角色名 'MYROLE123' 与另一个用户名或角色名发生冲突


SQL> create role myrole1234;

角色已创建。

SQL> --为myrole1234授权, create session create table create view
SQL> grant create session,create table,create view to myrole1234;

授权成功。

SQL> --创建用户
SQL> create user my1234 identified by password;

用户已创建。

SQL> grant myrole1234 to my1234;

授权成功。

SQL> spool off

上一篇:数据库变更管理


下一篇:linux那点事儿(五)----用户管理常用命令