您的位置:首页 > 数据库 > Oracle

Oracle学习笔记---用户管理

2015-01-08 16:09 781 查看

一、oracle安装会自动生成sys和system用户

1.sys用户

超级用户,具有最高权限,具有sysdba角色,有create database的权限,该用户默认密码是manager。

2.system用户

管理操作员,权限也很大,具有sysoper角色,没有create database的权限,默认密码是change_on_install。

3.一般来讲,对数据库的维护,使用system用户登录

NOTE:使用SQL Plus登录数据库时,system使用密码manager可直接登录。

但如果是sys用户,密码必须加上as sysdba,即完整密码为:change_on_install as sysdba

二、创建用户

一般是具有dba(数据库管理员)的权限才能使用
//---密码必须以字母开头,siuloonglee为用户名,xxx123是密码
create user siuloonglee indentified by xxx123;


创建的用户是没有权限的,甚至是没有登录数据库(有create session权限就可以登录数据库,connect角色)不能创建表(需要授权resource角色)

使用system/sys
//授权connect角色
grant connect to siuloonglee;
//授权resource角色
grant resource to siuloonglee;


connect角色有七个权限
select * from role_sys_privs where role='CONNECT';


(CREATE VIEW,CREATE TABLE,ALTER SESSION,CREATE CLUSTER,CREATE SESSION,CREATE SYNONYM,CREATE SEQUENCE,CREATE DATABASE LINK)

三、权限

分为系统权限,对象权限

1.系统权限

何为系统权限:用户对数据库的相关权限

通过角色授权,如connect角色,resource角色,dba角色

2.对象权限

用户对其他用户的数据对象操作的权限

如:siuloonglee用户不能去访问scott的emp表。

//---授权siuloonglee可以查询scott的emp表,必须在scott下授权
grant select on emp to siuloonglee;


在siuloonglee下可以执行

select * from scott.emp;


//---授权siuloonglee可以操作scott的emp表的所有权限,如增删改查
grant all on emp to siuloonglee;


如果scott想收回权限
//在scott下
revoke select on emp from siuloonglee;


权限传递

如果scott将emp表的权限授权给siuloonglee,还想让siuloonglee给其他用户授予emp表的权限。
//---如果是对象权限,就加入with grant option;
grant select on emp to siuloonglee with grant option;
---如果是系统权限,就加入with admin option;
grant connect to siuloonglee with admin option;


如siuloonglee将scott授予其对表emp的select权限授予yiautumn

//在scott下执行
grant select on emp to siuloonglee with grant option;
//在siuloonglee下执行
grant select on emp to yiautumn;
//在yiautumn下可以执行
select * from scott.emp;


NOTE:如若scott将授予siuloonglee对emp的select操作收回,则用户yiautumn也不能对emp操作。

四、修改密码

1.给自己修改密码
passw[ord]


2.给其他用户修改密码---必须具有dba的权限,或者是拥有alter user权限
alter user XXX indentified by xxx;


五、删除用户

在删除用户时,注意

1.不允许自己删除自己

2.如果该用户已经创建了表,那么就需要在删除时带一个参数cascade;


drop user XXX cascade;


使用profile管理用户口令

1.账户锁定

指定该账户(用户)登录时最多可以输入密码的次数,也可以指定用户锁定的时间(天),一般用dba的身份去执行命令。

创建profile文件---在system下
//---[lock_account]是profile文件的名字,3是次数,2是天数。
create profile lock_account limit failed_login_attempts 3 password_lock_time 2;


使用profile文件
alter user siuloonglee profile lock_account;


2.解锁
alter user siuloonglee account unlock;


3.制止口令

为了让用户定期修改密码可以使用终止口令来完成,同样这个命令也需要dba身份来操作。

例子:给创建的用户siuloonglee传建一个profile文件,要求该用户每隔10天要修改自己的登录密码,宽限期为2天。
create profile myprofile limit password_life_time 10 password_grace_time 2;
alter user siuloonglee profile myprofile;


4.口令历史

如果希望用户在修改密码时,不能使用以前使用过的密码,可使用口令历史,这样oracle就会将口令修改的信息存放在数字字典中,这样用户修改密码时,oracle就会对新旧密码进行比较,当发现新旧密码一样时,就提示用户重新输入密码。

建立profile
//---password_reuse_time 10表示指定口令可重用时间即10天后就可以重用
create profile password_history limit password_life_time 10 password_grace_time 2 password_reuse_time 10;


5.删除profile

当不需要某个profile文件时,可以删除
drop profile password_history [cascade];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: