sqlplus / as sysdba;//登陸sys帳戶 sqlplus sys as sysdba;//同上 sqlplus scott/tiger;//登陸普通用戶scott sqlplus / as sysdba;//登陸sys帳戶 sqlplus sys as sysdba;//同上 sqlplus scott/tiger;//登陸普通用戶scott 三、管理用戶
create user zhangsan;//在管理員帳戶下,創建用戶zhangsan alert user scott identified by tiger;//修改密碼 create user zhangsan;//在管理員帳戶下,創建用戶zhangsan alert user scott identified by tiger;//修改密碼 四,授予權限 1、默認的普通用戶scott默認未解鎖,不能進行那個使用,新建的用戶也沒有任何權限,必須授予權限
/*管理員授權*/ grant create session to zhangsan;//授予zhangsan用戶創建session的權限,即登陸權限 grant unlimited session to zhangsan;//授予zhangsan用戶使用表空間的權限 grant create table to zhangsan;//授予創建表的權限 grante drop table to zhangsan;//授予刪除表的權限 grant insert table to zhangsan;//插入表的權限 grant update table to zhangsan;//修改表的權限 grant all to public;//這條比較重要,授予所有權限(all)給所有用戶(public) /*管理員授權*/ grant create session to zhangsan;//授予zhangsan用戶創建session的權限,即登陸權限 grant unlimited session to zhangsan;//授予zhangsan用戶使用表空間的權限 grant create table to zhangsan;//授予創建表的權限 grante drop table to zhangsan;//授予刪除表的權限 grant insert table to zhangsan;//插入表的權限 grant update table to zhangsan;//修改表的權限 grant all to public;//這條比較重要,授予所有權限(all)給所有用戶(public) 2、oralce對權限管理比較嚴謹,普通用戶之間也是默認不能互相訪問的,需要互相授權
/*oralce對權限管理比較嚴謹,普通用戶之間也是默認不能互相訪問的*/ grant select on tablename to zhangsan;//授予zhangsan用戶查看指定表的權限 grant drop on tablename to zhangsan;//授予刪除表的權限 grant insert on tablename to zhangsan;//授予插入的權限 grant update on tablename to zhangsan;//授予修改表的權限 grant insert(id) on tablename to zhangsan; grant update(id) on tablename to zhangsan;//授予對指定表特定字段的插入和修改權限,注意,只能是insert和update grant alert all table to zhangsan;//授予zhangsan用戶alert任意表的權限 /*oralce對權限管理比較嚴謹,普通用戶之間也是默認不能互相訪問的*/ grant select on tablename to zhangsan;//授予zhangsan用戶查看指定表的權限 grant drop on tablename to zhangsan;//授予刪除表的權限 grant insert on tablename to zhangsan;//授予插入的權限 grant update on tablename to zhangsan;//授予修改表的權限 grant insert(id) on tablename to zhangsan; grant update(id) on tablename to zhangsan;//授予對指定表特定字段的插入和修改權限,注意,只能是insert和update grant alert all table to zhangsan;//授予zhangsan用戶alert任意表的權限 五、撤銷權限
select * from user_sys_privs;//查看當前用戶所有權限 select * from user_tab_privs;//查看所用用戶對表的權限 select * from user_sys_privs;//查看當前用戶所有權限 select * from user_tab_privs;//查看所用用戶對表的權限 七、操作表的用戶的表
/*需要在表名前加上用戶名,如下*/ select * from zhangsan.tablename /*需要在表名前加上用戶名,如下*/ select * from zhangsan.tablename
八、權限傳遞 即用戶A將權限授予B,B可以將操作的權限再授予C,命令如下:
grant alert table on tablename to zhangsan with admin option;//關鍵字 with admin option grant alert table on tablename to zhangsan with grant option;//關鍵字 with grant option效果和admin類似 grant alert table on tablename to zhangsan with admin option;//關鍵字 with admin option grant alert table on tablename to zhangsan with grant option;//關鍵字 with grant option效果和admin類似 九、角色 角色即權限的集合,可以把一個角色授予給用戶
create role myrole;//創建角色 grant create session to myrole;//將創建session的權限授予myrole grant myrole to zhangsan;//授予zhangsan用戶myrole的角色 drop role myrole;刪除角色 /*但是有些權限是不能授予給角色的,比如unlimited tablespace和any關鍵字*/