oracle用户权限操作sql汇总

—用户与权限管理—-

–1,用户–

create user 用户名identified by “口令”

default tablespace 表空间

—指定默认表空间,若不指定,则system表空间将被指定为用户的默认表空间,为了提高的性能,同时为了方便管理数据,oracle建议为用户指定一个默认表空间—

temporary tablespace 临时表空间

quota 空间配额大小 on 表空间

password expire

account lock|unlock

点击(此处)折叠或打开

create user user1 identified by”1234″

default tablespace users

temporary tablespace temp

quota 20m on users —若希望用户在所有表空间上都具有无限制的空间配额,则只要为其指定unlimited tablespaces权限即可—

password expire

account unlock;

–删除用户–

drop user 用户名

–需要注意的是,如果一个用户的模式中已经包含一些数据库对象,那么这个用户不能直接删除,必须指定cascade–

drop user scott cascade;

–用户的相关信息从数据字典视图dba_users中获得–

selectusername,password,default_tablespace,account_status from dba_users;

–修改用户口令–

password 用户名 –若没有指定用户名,则默认为当前用户–

alter user 用户identified by “新口令”

–alter也可以修改其它信息–

alter user user1

default tablespace ts1

temporary tablespace ts1

quota unlimited on ts1;

–系统权限的管理–

–为用户授予权限的grant命令语法–

grant 权限1,权限2,… to 用户1,用户2,… with admin option; –with admin option的好处是权限的获得者可以再将权限授予其他用户–

—权限包括系统权限和对象权限–

–系统权限–

create session,create table,createresource,create view,create user,create trigger,create tablespace,createprocedure.

alter session,database,user

–为了使一个用户可以操作数据库,至少需要有create session,create table和有指定(表)空间配额的3个权限–

grant create session,create table,unlimitedtablespace to 用户名;

–回收权限–

–注意:系统权限可以转授,但是回收时不能间接回收–

revoke 系统权限1,系统权限2 …

from 用户1,用户2 …

–对象权限 主要是对数据库对象中的数据的访问权限,这类权限主要针对普通用户–

grant 对象权限1(列名),对象权限2(列名)…

on 对象 to 用户1,用户2… with grant option

grant select on dept to user1 with grantoption

grant insert(empno),update(sal) on emp touser1,user2

grant execute on functional to user1

–回收权限–

–权限insert,update,references在分配时可以指定相关的列,但在回收时不能指定列,而只能指定表名–

revoke 对象权限1,对象权限2… on 对象

from 用户1,用户2…

revoke update(sal) on emp from user2 –错误语句–

revoke update on emp from user2

–数据库中所有的系统权限–

select name from system_privilege_map;

–sys从数据字典视图dba_sys_privs中查询任何用户所具有的系统权限–

select grantee,privilege,admin_option fromdba_sys_privs where grantee=’scott’

—-普通用户通过user_sys_privs查询 用户直接获得的系统权限,即通过grant命令授予当前用户的系统权限—

select username,privilege,admin_option fromuser_sys_privs

–从数据字典视图session_privs中可以查询一个用户在当前会话中所具有的系统权限–

— session_privs权限==直接获得的权限 + 該用户从角色中间接获得的系统权限 —

–对象权限有关的数据字典视图:dba_tab_privs,dba_col_privs,user_tab_privs和user_col_privs–

点击(此处)折叠或打开

— dba_tab_privs 查询任何用户所具有的对象权限 —

selectgrantee,privilege,grantor,table_name,grantable from dba_tab_privs

where grantee=’user1′;

–dba_col_privs 查询用户在列上的权限 —

selectgrantee,table_name,column_name,privilege,grantor,grantable

from dba_col_privs where grantee=’user1′;

selectgrantee,table_name,column_name,privilege,grantor,grantable

from user_tab_privs where grantee=’scott’;

–角色–

–connect角色 包含的权限有createsession —

/* resource角色 包含的权限有 crate sequence,create trigger,create cluster,create procedure,

create type,create operator,create table,create indextype */

create role 角色名

drop role 角色名

grant select on emp to role1

revoke select on emp from role1

–角色信息的查询–

/* dba_roles 记录数据库中所有角色

dba_role_privs 记录所有被授予用户或另一角色的角色

user_role_privs 记录所有被授予当前用户的角色

role_role_privs 记录一个角色中包含的其他角色

role_sys_privs 记录一个角色中包含的系统权限

role_tab_privs 记录一个角色中包含的对象权限

session_roles 记录当前会话中所使用的角色 */

–获得系统中所有的角色–

select role from dba_roles

–查询用户user1所拥有的角色和默认角色–

select granted_role,default_role fromdba_role_privs where grantee=’user1′

–查询角色connect所包含的系统权限–

select privilege,admin_option fromrole_sys_privs where role=’connect’

–profile的管理–

–查询用户的会话信息,强制终止用户会话,锁定用户帐号–

select username,sid,serial# from v$sessionwhere username=’scott’;

alter system kill session ‘144,7’; –144和7分别为用户会话的sid和serial#–

alter user scott account lock;

–profile创建–

create profile profile名称 limit

口令限制

资源限制

–指定profile 每个用户只能指定一个profile–

create user user2 identified by”1234″ profile p1

alter user scott profile p1

–从数据字典dba_users中可以获得为每个用户指定的profile-

select profile from dba_users whereusername=’scott’;

–数据字典dba_profiles–

select resource_name,limit fromdba_profiles where profile=’p1′;

–删除profile–

drop profile profile名字 [cascade];

–profile限制–

/* failed_login_attempts 允许的失败登录次数,默认值为10次

password_lock_time 账号锁定时间,默认值为1天

password_life_time 口令的有效期,默认值为180天

password_grace_time 口令有效期的延长期,默认值为-周、7天

password_reuse_time 为了再次使用过去用过的口令,必须经过的天数

password_reuse_max 为了再次使用过去用过的口令,必须使用不同口令的次数

password_reuse_time 和 password_reuse_max 必须一起使用 */

–如果用户失败的登录次数达到3次,则用户账号将被锁定5天–

create profile p1 limitfailed_login_attempts 3 password_lock_time 5

–用户在30天内必须把口令修改过5次后,才能使用过去用过的口令–

create profile p2 limit password_reuse_time30 password_reuse_max 5

–利用profile对用户使用资源进行控制–

如果要使profile对用户使用系统资源起限制作用,则需要将参数resource_limit的值设置为true

alter system set resource_limit=true

sessions_per_user 一个用户所允许的并发会话数目

cpu_per_session 用户在一个会话内所使用的cpu时间的总和,时间单位为0.01秒

logical_reads_per_session 用户在一个会话内所能访问的数据块的数量(包括物理读和逻辑读的数量)

connect_time 一个用户会话所能持续的时间,以分钟为单位;超过这个时间,会话将自动断开

idle_time 一个用户会话所允许的连续的空闲时间,以分钟为单位,超过这个时间,会话将自动断开

private_sga 如果数据库服务器的连接模式为共享模式,这个参数用来限制为一个用户会话所分配的sga空间

cpu_per_call 用户执行的每条命令所使用的cpu时间,时间单位为0.01秒

logical_reads_per_call 用户执行的每条命令所能访问的数据块的数量

如果能够对用户消耗cpu时间、访问数据块的数量等这些资源进行限制,那么就可以有效地

防止诸如死循环的执行、访问一个大表中的所有数据这类情况的发生。

create profile p3 limit

sessions_per_user 100

logical_reads_per_session 500

connect_time 5

create profile p4 limit

cpu_per_call 10

logical_reads_per_call 50

/* 若没有为用户指定profile文件,则用户会受默认profile限制,如果要对所有用户进行同样的限制,那么只要修改

这个默认profile所包含的限制,并且不要为用户指定其他的profile */

select resource_name,limit fromdba_profiles where profile=’default’;

(0)
上一篇 2022年3月22日
下一篇 2022年3月22日

相关推荐