oracle數據庫如何創建用戶和角色,並給其賦權?


一、創建用戶並賦予權限

1、創建用戶

create user wangxiangyu identified by wangxiangyu;

2、賦權

grant dba to wangxiangyu;

grant create session to wangxiangyu; --會話權限(沒有該權限無法登錄)

3、查看已經賦予用戶的系統權限

select * from user_sys_privs;

二、創建角色

角色,即權限的集合,可以把一個角色授予給用戶

1、創建角色

create role myrole;

2、賦權

grant create session to myrole;--將創建session的權限授予給角色myrole

3、賦角色給用戶

grant myrole to zhangsan;--授予zhangsan用戶myrole的角色

4、刪除角色

drop role myrole;

查看所有用戶

select * from dba_users;

select * from all_users;

select * from user_users;

alter user user_name account lock; 鎖住用戶

alter user user_name account unlock; 解鎖用戶

查詢當前用戶所擁有的權限

select * from session_privs;

查看用戶被賦予的系統權限(直接賦值給用戶或角色的系統權限)

select * from dba_sys_privs where grantee = 'RESOURCE';

select * from user_sys_privs;

注:USER_SYS_PRIVS 視圖列出已經授予用戶的系統權限。

它的列包括Username、Privilege和 Admin_Option(設置為YES 或NO 的一個標志,用來指出是否用with admin option 授予權限),直接授予用戶的所有系統權限都可以通過該視圖顯示,通過角色授予用戶的系統權限不能在此視圖中顯示。

查看所有角色

select * from dba_roles;

查看用戶所擁有的角色

select * from session_roles order by role;--返回當前用戶被授予的全部角色, 包括嵌套授權的角色

select * from dba_role_privs;

select * from user_role_privs;

查看當前用戶角色所包含的權限

select * from role_sys_privs where role = 'CONNECT';

查看用戶對象權限

select * from dba_tab_privs;

select * from all_tab_privs;

select * from user_tab_privs;

查看哪些用戶有sysdba或sysoper系統權限(查詢時需要相應權限)

select * from v$pwfile_users;

查看用戶與默認表空間的關系

select username, default_tablespace from dba_users where username='SCOTT';

查看當前用戶的表

select * from user_tables;

可視化賦權:

1、使用ins用戶建表

2、使用mobapp用戶(管理員)將ins用戶的某個表賦權給odso用戶

users——>ins,選中要賦權的表賦權(右鍵,編輯,權限)

等同於:grant select, insert, update, delete on ins.tb_cablecheck_equ_odso to odso;

3、使用odso用戶登錄,增刪改查該表測試

 

命令賦權:

賦予權限:grant ... to ...

撤銷權限:revoke ... from ...

登陸

grant create session to zhangsan;

使用表空間

grant unlimited tablespace to zhangsan;

創建表

grant create table to zhangsan;

刪除表

grant drop table to zhangsan;

grant drop on table_name to user_name;

插入表

grant insert table to zhangsan;

grant insert on table_name to user_name;

grant insert(id) on table_name to user_name;

更新表數據

grant update table to zhangsan;

grant update on table_name to user_name;

grant update(id) on table_name to user_name;

修改表結構

grant alter table on table_name to user_name;

查詢表

grant select on table_name to user_name;

創建過程

grant create any procedure to username;

執行過程

grant execute any procedure to username;

grant execute on ins.p_trun_link_odso  to odso_insert;

授予所有權限(all)給所有用戶(public)

grant all to public;

權限傳遞

即用戶A將權限授予B,B可以將操作的權限再授予C,

命令如下:

grant alter table on table_name to user_name with admin option;

grant update on table_name to user_name with grant option; --轉移更新權限

grant alter table on table_name to user_name with grant option;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM