用戶本身管理
增
create user C##jaovo identified by jaovo123; //sys,system
密碼必須以字母開頭
刪
不能自己刪除自己
刪除要門是DBA,或者drop user權限
drop user C##用戶名 cascade;
如果要刪除的用戶下已經有表,就必須帶有參數cascade會把表和用戶一起刪除
改
修改自己密碼: password ; //系統用戶,或者有alter權限
給別人修改密碼,據需要權限:dba或者alter user權限
alter user c##scott identified by root;
password 用戶名(新版本不能使用)
查
當前用戶下所有的表:select * from user_tables;
顯示當前數據庫的所有表:select * from tab;
select * from dba_users; 查看數據庫里面所有用戶,前提是你是有dba權限的帳號,如sys,system
select * from all_users; 查看你能管理的所有用戶!
select * from user_users; 查看當前用戶信息 !
用戶權限管理
基本原理
什么是權限:就是你能不能操作某條SQL語句
系統權限(用戶管理權限)
140多個
對象權限
用戶對不屬於他的數據對象進行操作的權限(其他用戶的數據操作的權限,跨部門)
20多個
授權關鍵字:grant
創建關鍵字:create
增
grant connect to C##用戶名
grant 操作名 on 表名 to 用戶名;
表操作:增刪改查/所有,select,update,insert,delete,all
grant 操作名 on 表名 to 用戶名 with grant option;
該權限可以有被授予者授予給別人
權限的傳遞
刪
收回賦予給某個用戶的權限,(三個用戶)
級聯授權的,會級聯收回
revoke 操作名 on 表名 from 用戶名
revoke select on emp from us_test;
用戶綜合管理案例
1 創建用戶,默認創建在哪個數據庫里面,但是默認沒有任何權限,不能登錄任何數據庫的,需要授權
2 為其制定相應的權限,需要sys/system用戶賦予權限
grant connect to miaoming
4 grant resource to xiaoming;
grant unlimited tablespace to xiaoming;
select * from user_tables
3 create table TestTable(userId varchar2(30),userName varchar2(30));
5 查看表的列:desc test;
6 grant select on c##scott.emp to xiaoming;(sys,system,表所有者,scott)
insert into c##scott.emp(userId,userName) values(123,hello);
7 select * from c##scott.emp;
8 收回權限(有權限的人都可以收回):revoke select on emp from xiaoming
9 權限傳遞:grant select on emp to xiaoming with grant option
10 如果授權在上級被會收,下一級也會被回收
11 把測試用戶刪除掉:drop user C##用戶名 cascade;
用戶密碼管理(profile)
profile:用戶密碼管理文件,用於強制對用戶密碼進行管理,步驟是創建文件,賦予文件
數據庫創建時,會自動創建默認的profile選項:default,建立用戶是如果沒有指定profile選項,就會分配default
用戶鎖定
創建規則,使用規則
用戶嘗試3次鎖定兩天:lock_account:可變,3,2可變
create profile c##lock_account limit failed_login_attempts3 password_lock_time 2;
指定限制給某個用戶:alter user xiaoming profile aaa;
解鎖:alter user 用戶名 account unlock;解鎖(系統用戶)
強制改密碼(終止口令).dba身份
create profile 規則名 limit password_life_time 10 password_grace_time 天數;
alter user 用戶名 profile 規則名
密碼強度和密碼歷史
create profile password_history(規則名) limit password_life_time 10密碼有效天數 password_grace_time 2寬限天數 password_reuse_time 10可再用天數;
alter user 用戶名 profile 規則名
增
create profile 規則名稱 limit failed_login_attempts 錯誤次數 password_lock_time 鎖定天數
alter user 用戶名 profile 規則名; //加鎖
alter user 用戶名 account unlock; //解鎖
刪
drop profile password_history/名字 (cascade); //所有用戶不在約束
密碼管理綜合案例
create user c##jaovo
2 鎖定密碼
1 創建規則
create profile drop profile password_history/名字 (cascade);t limit failed_login_attempts3 password_lock_time 2;
2 指定規則
alter user 用戶名 profile 規則名
3 輸錯密碼
4 級聯刪除規則:
drop profile password_history/名字 (cascade);
3 強制修改密碼
1 創建規則
create profile password_history(規則名) limit password_life_time 10密碼有效天數 password_grace_time 2寬限天數 password_reuse_time 10可再用天數;
2 指定規則
alter user 用戶名 profile 規則名
4 級聯刪除規則:
drop profile password_history/名字 (cascade); //所有用戶不在約束
4 刪除用戶
基於角色的權限管理
基本原理
和linux操作系統權限控制差不多
把各個權限打包,繼承到某個角色上,給用戶賦予這個角色,用戶就擁有了這些權限.
重要角色
預定義角色
resource
數據庫內部資源操作權限
connect
連接權限
dba
數據庫管理員權限
