Oracle用户、权限、角色管理
一、权限分类:
系统权限:系统规定用户使用数据库的权限。(系统权限是对用户而言)。
1、系统权限分类:
DBA: 拥有全部特权,是系统最高权限,只有DBA才可以创建数据库结构。
对于DBA管理用户:授予connect,resource, dba权限。
[系统权限只能由DBA用户授出:sys, system(最开始只能是这两个用户)]
授权命令:SQL> grant connect, resource, dba to 用户名1 [,用户名2]...;
SQL> connect system/manager
SQL> Create user user50 identified by user50;
SQL> grant connect, resource to user50;
SQL> select * from dba_role_privs;
SQL> select * from dba_sys_privs;
SQL> select * from role_sys_privs;
增加WITH ADMIN OPTION选项,则得到的权限可以传递。
命令:SQL> Revoke connect, resource from user50;
1、实体权限分类:select, update, insert, alter, index, delete, all //all包括所有权限
execute //执行存储过程权限
SQL> grant select, update, insert on product to user02;
SQL> grant all on product to user02;
SQL> select * from user01.product;
3. 将表的操作权限授予全体用户:
SQL> grant all on product to public; // public表示是所有的用户,这里的all权限不包括drop。
SQL> select owner, table_name from all_tables; // 用户可以查询的表
SQL> select table_name from user_tables; // 用户创建的表
SQL> select grantor, table_schema, table_name, privilege from all_tab_privs; // 获权可以存取的表(被授权的)
SQL> select grantee, owner, table_name, privilege from user_tab_privs; // 授出权限的表(授出的权限)
DBA用户:
SQL> Create table stud02.product(
id number(10),
name varchar2(20));
SQL> drop table stud02.emp;
as
select * from scott.emp;
5. 实体权限传递(with grant option):
user01:
user01:
SQL>Revoke select, update on product from user02; //传递的权限将全部丢失。
一、创建用户的Profile文件
SQL> create profile student limit // student为资源文件名
FAILED_LOGIN_ATTEMPTS 3 //指定锁定用户的登录失败次数
PASSWORD_LOCK_TIME 5 //指定用户被锁定天数
PASSWORD_LIFE_TIME 30 //指定口令可用天数
SQL> Create User username
Identified by password
Default Tablespace tablespace
Temporary Tablespace tablespace
Profile profile
Quota integer/unlimited on tablespace;
SQL> Create user acc01
identified by acc01 // 如果密码是数字,请用双引号括起来
default tablespace account
temporary tablespace temp
profile default
quota 50m on account;
SQL> grant connect, resource to acc01;
SQL> select username, default_tablespace, temporary_tablespace from dba_users;
SQL> select * from dba_profiles;
资源文件类似表,一旦创建就会保存在数据库中。
SQL> select username, profile, default_tablespace, temporary_tablespace from dba_users;
failed_login_attempts 5
idle_time 5;
SQL> Alter user acc01 profile common;
SQL> Alter User 用户名
Identified 口令
Default Tablespace tablespace
Temporary Tablespace tablespace
Profile profile
Quota integer/unlimited on tablespace;
1、修改口令字:
SQL>Alter user acc01 identified by "12345";
SQL> Alter user acc01 default tablespace users;
SQL> Alter user acc01 temporary tablespace temp_data;
SQL> Alter user acc01 password expire;
SQL> Alter user acc01 account lock; // 加锁
SQL> Alter user acc01 account unlock; // 解锁
SQL>drop user 用户名; //用户没有建任何实体
SQL> drop user 用户名 CASCADE; // 将用户及其所建实体全部删除
五、监视用户:
1、查询用户会话信息:
SQL> select username, sid, serial#, machine from v$session;
SQL> Alter system kill session ‘sid, serial#‘;
SQL> select user_name, sql_text from v$open_cursor;
NLS_LANGUAGE= ‘SIMPLIFIED CHINESE‘
NLS_TERRITORY= ‘CHINA‘
NLS_CURRENCY= ‘RMB‘
NLS_ISO_CURRENCY= ‘CHINA‘
NLS_NUMERIC_CHARACTERS= ‘.,‘
NLS_CALENDAR= ‘GREGORIAN‘
NLS_DATE_FORMAT= ‘yyyy-mm-dd dy‘
NLS_DATE_LANGUAGE= ‘SIMPLIFIED CHINESE‘
NLS_SORT= ‘BINARY‘
TIME_ZONE= ‘+08:00‘
NLS_DUAL_CURRENCY = ‘RMB‘
NLS_TIME_FORMAT = ‘HH.MI.SSXFF AM‘
NLS_TIMESTAMP_FORMAT = ‘DD-MON-RR HH.MI.SSXFF AM‘
NLS_TIME_TZ_FORMAT = ‘HH.MI.SSXFF AM TZH:TZM‘
NLS_TIMESTAMP_TZ_FORMAT = ‘DD-MON-RR HH.MI.SSXFF AM TZH:TZM‘
SQL> grant connect, resource, dba to acc01;
Identified by password/ Not Identified;
SQL> Alter Role <role_name> ...
All Except <role_name2> / None
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。