study of oracle lesson one,oraclelesson

來源:互聯網
上載者:User

study of oracle lesson one,oraclelesson

oracle學習第一部分

1.oracle簡介

1.1 目前常用資料庫分類

小型資料庫:sql server,access(微軟的)

中型資料庫:mysql(瑞典公司的),sybase(美國sybase公司)

大型資料庫:informix(IBM),oracle(甲骨文公司),db2(IBM)

1.2 oracle資料庫介紹

oracle資料庫是由美國甲骨文公司的產品,公司從1970年起開始開發資料庫,目前資料庫已經發展到oracle 11G,比較流行的是oracle 9i和oracle 10g,oracle單詞的意思是神喻,代神說話的人,甲骨文

1.3 oracle資料庫資質認證

a. oca    oracle低級認證

b. ocp oracle中級認證

c. ocm oracle進階認證(很難考,報名費很貴,2000美金左右,中國大陸還不一定有考區)

2. oracle資料庫的安裝

2. 預設使用者

oracle資料庫安裝以後,會預設有三個使用者

dba使用者:資料庫管理員,擁有資料庫最高許可權,其可以create database許可權,也可以稱為超級使用者,sysdba角色,使用者密碼分別如下:

sys/change_on_install

sysoper使用者:資料庫使用者管理員,許可權也很大,但是沒有create database的許可權,使用者密碼分別如下:

system/manager

scott使用者:普通使用者,oracle會給其預設產生一些資料對象,使用者密碼分別是:

scott/tiger

註:一般的,對資料庫的維護和操作,使用system使用者就可以了

3.oracle資料的啟動

a.啟動資料庫執行個體

b.啟動資料庫監聽

4.串連資料庫

a.sqlplus可以串連

b.PL/SQL可以串連

...

5.常用命令

a.常用系統命令:

(1)顯示目前使用者:show user;

(2)串連資料庫:    conn(connect)  使用者名稱/密碼;

 (3)修改密碼:passw(password) 使用者名稱;

   (4) 查看目前使用者下面有哪些表:

select table_name from user_tables;

  (5)設定環境變數

設定行寬:set pagesize = 120;

設定頁面大小:set pagesize = 8;//一頁顯示8條資料,包括最後一個空白行

b.檔案互動命令

(1) 互動式命令:&

可以替代變數,而該變數在執行時,需要使用者輸入

select * from emp where job=‘&job’;

(2)執行指令碼命令:start 或者@

@ D:\my.sql;

start d:\my.sql;

(3)修改sql指令碼命令:edit

edit D:\my.sql;   //開啟指令檔,然後使用者就可以修改了

(4)重新導向: spool,將命令列的輸出重新導向輸出到檔案中,需要兩步操作

spool   filename;//建立新檔案filename

spool off; //輸出到檔案中

   c.操作使用者語句

(1) oracle使用者建立:只有sys或者system使用者有許可權建立使用者

create user liudh identified by m123; //建立使用者liudh,密碼為m123,注意:oracle資料庫中密碼必須以字母開頭

(2)修改密碼

                  password  使用者名稱;

(3) 刪除使用者,一般是串聯刪除

drop user 使用者名稱 cascade;

d.授權操作,資料庫管理員才有的許可權,建立使用者預設資料表空間是system空間

(1)grant connect to liudh;//給使用者liudh授予connect角色的許可權,connect是一個角色,這個角色有一些7種許可權,比如串連資料庫等

(2)查看錶結構

desc tablename;

(3)授權訪問其他使用者的表許可權

grant select on emp to liudh;//emp表是scott使用者的,執行該操作以後,liudh使用者就可以查詢(select)scott使用者下的表emp

grant update on emp to liudh;


使用all可以授予多個對象許可權,包括的對象許可權有:select,update,delete,create

grant all on emp to liudhu;

(4) 操作其他使用者的表,要帶上使用者名稱

liudh使用者想要查詢scott使用者的emp表,在授予許可權的情況下,可通過如下語句來實現:

select * from scott.emp;

(5)許可權資源回收:invoke

revoke select on emp from liudh;//scott使用者取消liudhy使用者對自己的表emp的select對象許可權

注意:許可權的回收是級聯的

scott 將select 表emp的許可權傳遞授予liudh,liudh將對scott表emp的select對象許可權授予zhangxy,當scott回收liudh該許可權時,zhangxy的許可權也被收回了

,即許可權的收回是級聯的


(6)許可權的傳遞,許可權的維護 使用with grant option 和 with admin option

scott使用者把對自己的表emp的select對象許可權授予liudh,同時也希望liudh使用者把對emp表的select對象許可權授予其他人,比如zhangxy,語句如下

對象許可權的傳遞:

grant select on emp to liudh with grant option;

系統許可權的傳遞:

grant connect to liudh with admin option;//資料庫管理員將connect系統許可權授予liudh,而後liudh就可以將connect系統許可權授予其他普通使用者


6.oracle使用者管理

oracle安裝預設會產生三個使用者,也會產生一個資料庫執行個體,該執行個體下面可以增加其他使用者,然後使用者就可以在該執行個體下建資料對象,是共用資料表空間的,

每個使用者在這個執行個體下面有自己可以操作的表,不同使用者自己專有的表資料對象名可以相同,每個使用者都有自己的許可權,其中許可權分為系統許可權和對象許可權(對資料

對象操作的許可權)

資料對象包括:表,預存程序,視圖,函數,序列,觸發器,角色,資料表空間,工作,包等


7.oracle使用者口令管理

通過建立profile檔案來實現,profile是口令限制,資源限制的命令的集合

(1)賬戶鎖定

建立profile規則aaa:使用者輸錯三次密碼,賬戶鎖定兩天

create profile aaa limit  faild_login_attempts 3 password_lock_time 2;

將鎖定規則aaa給使用者liudh

alter user liudh profile aaa;//註:此處的profile是一個關鍵字

(2)賬戶解鎖:(只有dba有許可權)

alter user  liudh  account unlock;


(3)  終止口令:

強制讓使用者每隔10天修改一次密碼,期限為2天

create profile bbb limit password_life_time 10 password_grace_time 2;

將規則bbb授予使用者liudh

alter user liudh profile bbb;


(4)口令曆史:

如果使用者修改密碼,不能和前一次一樣,10天之後才可以修改為相同的

 create profile passwordtime limit password_life_time 10 password_grace_time 2 password_reuse_time 10;

刪除profile規則,一般是串聯刪除

drop profile passwordtime cascade;//串聯刪除









 












相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.