oracle数据库的连接,用户的管理与权限的简单命令

orcale命令结束符为分号

 

 --------------------------------------------连接数据库的相关命令--------------------------------------------------

 

当只有一个默认数据库存在时建立连接命令:   conn   用户名/密码  
                                                      eg:   conn scott/tiger
如果有多个数据库存在时要建立连接用命令: conn   用户名/密码@数据库的名字

                                                       eg:  conn system/sa@lmsdb;

 

断开数据库的连接;disc [onnect]

 

退出oracle:exit ;

 

 

 

--------------------------------------------关于用户的常用命令-----------------------------------------------------

显示用户名:show user;

 

创建用户:create user ** identified by **;
*只有sysdba有权限创建用户,用户名不能用数字开头
eg:create user xiaoming identified by m123;

 

用户修改自己的密码:passw(ord)

dba修改其他用户的密码: alter user lms identified by mm;
*自己可以修改自己用户密码
如果想修改其他人的密码需要具有dba的权限(即必须用sys/system登录)或者该用户拥有alter user的系统权限
修改密码的时候只需要输入命令passw就行了,他会提示你相关操作

 


删除用户;drop  user 用户名 【cascade】
*一般以dba的身份去删除某个用户,如果其他用户去删除用户则需要具有drop user的权限
在删除用户时,注意;如果要删除的用户已经创建了表,就需要在删除的时候带一个参数 cascade

 

 

 

------------------------------------------------用户的权限----------------------------------------------------

 


新创建的用户是没有任何权限的,甚至连登录数据库的权限都没有,需要为其制定相应的权限
给一个用户赋予权限用命令grant,回收权限使用命令revoke

 

常见的预定义特权:connect(连接数据库的特权),resource(建表以及增删改查等一系列的特权),(dba)超级管理员的特权
*只有sys与system有这个赋予这些预定义特权给其他用户的的权利
        eg:create user xiaoming identified by m123
        eg:grant connect to xiaoming
        eg:grant resource to xiaoming

 

常见的对象权限有:select, insert ,update ,delete, all ,create index........
       eg:grant select on emp to xiaoming           //将表emp的查询权限授权给小明
       eg:grant all on emp to xiaoming                // 赋予小明对于emp表的crud的特权
*有权给其他用户赋予crud权限的除了表的拥有者还有sys和system


被授予查询权限的用户去查询该表时候的语法如下;
select * from scott.emp                                      //引入方案的概念

收回xiaoming的特权:
revoke select on emp from emp

 

 

---------对权限的维护---------
例如希望xiaoming能把被授予的权限传递给其他用户

*如果是对象权限用 with grant option 命令
scott给小明权限时
eg:grant select on emp to xiaoming with grant option
       conn system/manager
       create user xiaohong identified h123
       grant connect to xiaohong
       conn xiaoming/m123
       grant selecct on scott.emp to xiaohong
       conn xiaohong/m123
       select * from scott.emp

*如果是系统权限用 with admin option 命令
system给小明权限时
eg:grant select on scott.emp to xiaoming with admin option

如果scott把小明对emp表的权限回收了,那么小红的权限也被回收了(级联回收权限)

scott授予的权限,system能否收回?答案是能
*Oracle系统权限不具有级联收回的功能,非系统权限具有级联回收功能

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章