【Oracle】第一章建立授權,oracle第一章授權

來源:互聯網
上載者:User

【Oracle】第一章建立授權,oracle第一章授權

ORACLE 第一章建立授權

通過命令查看控制檔案,資料檔案,記錄檔:

  控制檔案 : Desc v$controlfile;

  資料檔案 :desc v$datafile;

  記錄檔: desc v$logfile;

1. 執行匯入  .sql檔案

    命令文法如下:

          directory_path\store_schema.sql

    其中 directory_path 是儲存 store_schema.sql 指令碼的目錄和路徑 

    例如:以下代碼示範了匯入C盤下的 sql 指令檔:

          @c:\sql\store_schema.sql

2.  在SQL Plus 中切換不同的使用者,例如以下命令切換到 system 使用者登陸

connect system/manager@oracle 其中oracle 是指服務名

3. oracle 安裝後,dual 是預設的表名 在SQL Plus 中輸入:

    select sysdate from dual;

   它可以返回當前日期

**** 注意:SQL語句以分號(;)結束

4. oracle 中的資料庫是以資料表空間存在的,以下命令建立了一個名為:yyaccp的資料表空間,並且指定資料檔案的路徑。

    create tablespace yyaccp

    datafile 'D:\oracle\oradata\oracle\yyaccp.DBF'

    size 5M autoextend on;

5. oracle 中可以通過命令建立使用者名稱,以下命令建立了一個 yyaccp 使用者名稱,

   並為它確定預設資料表空間和暫存資料表空間

      create user yyaccp identified by yyaccp

      default tablespace yyaccp

      temporary tablespace temp;

6. 如果要給授權的使用者可以在資料庫中執行一定的操作那麼應該為該使用者授予

   執行這些操作的許可權,例如,如果要讓這個使用者串連到資料庫上必須要為該

   使用者授予“建立會話的許可權”,以下命令為 yyaccp 使用者建立了會話許可權

   (使用grant語句)

        grant create session to yyaccp;

    授予許可權以後就可以通過 yyaccp 使用者串連到資料庫了:

       connect yyaccp/yyaccp@oracle;

7.使用者密碼的可以通過 alter 進行修改 以下命令修改了 yyaccp 使用者的密碼:

     alter user yyaccp identified by accp;

8. password 命令可以用來修改當前登陸的使用者的密碼,在登陸後輸入password

  命令,sql plus 會提示輸入原來的密碼,然後再輸入兩次新密碼 例如:

    connect yyaccp/accp;

   輸入: password;

   sql plus 顯示:

       更改YYACCP的口令

       舊口令: ******

       新口令: ******

       重新鍵入新口令:******

       口令已更改

9. 刪除使用者可以通過 drop user 進行刪除,以下命令刪除 yyaccp 使用者

   connect system/manager@oracle;

   drop user yyaccp;

10. 使用 grant向使用者授予不同的特權:以下通過system 使用者向 yyaccp 使用者授予了 建立會話、建立使用者以及建立表的許可權

    Connect system/manager@oracle;

    Grant create session, create user , create table to yyaccp;

     

   常用的系統特權:

Create  session

 串連到資料庫上

Create  sequence

 建立序列

Create table

建立表

Create any table

在任何模式中建立表

Drop table

刪除表

Drop any table

刪除任何模式中的表

Create procedure

建立預存程序

Execute any  procedure

執行任何模式中的儲存 過程

Create user

建立使用者

Drop user

刪除使用者

Create view

建立視圖

11.使用with admin option 選項。授權的使用者可以把特權授予其他使用者使用 

   以下命令 將execute any procedure 特權授予 yyaccp 使用者,同時指定了 

   with admin option 選項。

Connect system/manager@oracle;

  Grant execute any procedure to yyaccp with admin option;

12. 檢查授予使用者的許可權(通過 user_sys_privs 表)檢查某個使用者具有哪些許可權:

   以下命令示範了 yyaccp 使用者串連到資料庫上,並對 user_sys_privs 進行查詢

Connect  yyaccp/accp@oracle;

Select * from user_sys_privs ;

   

14. 撤銷系統特權。以下system撤銷了 yyaccp使用者的dba許可權

    Revoke dba from yyaccp;

   

15.當授權的使用者向資料表空間建立表或向已有的表中插入資料時,仍然提示許可權不足可以通過以下方式解決例如 :建立了 yyaccp 使用者 但是yyaccp 使用者在 yyaccp 資料表空間中建表時出現許可權不足,執行以下命令:

connect system/manager;

alter user yyaccp quota unlimited on yyaccp;

使用以下命令刪除資料表空間同時刪除資料表空間對應的資料檔案:

     drop tablespace yyaccp including contents and datafiles;

對象特權:

16.   對象特權允許使用者對資料庫物件執行特定的操作,比如對錶進行添加、修改、刪除、查詢等操作。

以下表格列出了常用的對象特權:

對象特權

允許執行的操作

select

執行查詢操作

Insert

執行插入操作

Update

執行修改操作

Delete

執行刪除操作

execute

執行預存程序

向使用者授予對象特權:

17. 可以使用 grant 語句向使用者授予 對象特權 ,下面這個例子以 yyaccp 使用者的身份串連到資料庫,並向 tuser 授予以下特權:對 tusertable 表的 select ,

Insert ,update 對象特權進行授權

   Connect yyaccp/accp;

   Grant select ,insert ,update on yyaccp.tusertable to tuser;

 

18. 以下命令對tusertable 表中的 name , address 列的 update 特權授予tuser 使用者

Grant update(name,ddress) on yyaccp.tusertable to tuser;

19. 使用 grant 選項可以使授權的使用者把這種特權再授予其他使用者。下面命令對tusertable 表的 select 特權授予 tuser 使用者,同時指定了 with grant option 選項

   Grant select on yyaccp.tusertable to tuser with grant option

20. 檢查已授予的對象特權(通過查詢 user_tab_privs_made) 可以檢查某個使用者對哪些表向其他使用者開放了哪些對象特權:

   Select  * from user_tab_privs_made 

user_tab_privs_made 部分列

列名稱

說明

Grante

該特權授予的使用者

Table_name

所授予的特權所操作的對象(例如表)名

Grantor

授權者

Privilege

對該對象授予的特權

grantable

特權所授予的使用者是否可以將這種特權再授予其他使用者,該值等於  yes 或 no

hierarchy

特權是否構成層次關係。該值等於 yes 或 no

User_col_privs_made 可以檢查某個使用者對哪些列對象開放了哪些特權。

   Select * from user_col_privs_made;

from user_col_privs_made 部分列 

列名稱

列說明

Grantee

該特權授予的使用者

Table_name

所授予特權所操作的對象名

Column_name

所授予特權所操作的對象名

Grantor

授權者

Privilege

對該對象授予的特權

grantable

特權授予的使用者是否可以將這種許可權再授予其他使用者,該值等於 yes 或 no

如果以tuser 使用者身份串連到資料庫上就可以通過公用對象名稱 sttable 對 yyaccp.sttable 進行檢索:

   Connect tuser/tuser;

   Select * from sttable;

23.撤銷使用者物件的特權:

   使用 revoke 語句撤銷某個使用者的對象特權。以下命令以 yyaccp 使用者的身份串連到資料庫上,並撤銷  tuser 對sttable 表的 insert  特權

Connect  yyaccp/accp;

Revoke insert on sttable from tuser

Oracle 資料庫中的 資料區塊、區、段、資料表空間 

在最細的粒度上,Oracle儲存資料到資料區塊中(也叫邏輯塊、Oracle塊或頁),一個資料區塊對應磁碟上的一定數量位元組的資料庫實體儲存體空間。 

  邏輯資料庫儲存空間的下一個儲存層級是區。一個區是分配用來儲存特定資訊的連續資料區塊。 

  區之上的邏輯資料庫儲存層級叫段。一個段是區的集合,每個區都被分配了特定的資料結構,所有的區都儲存在同一資料表空間中。例如,每個表的資料被儲存在它自己的資料區段中,每個索引的資料存放區在它自己的索引段中。假如表或索引是分區的,每個分區被儲存在它自己的段中。 

  Oracle以區為單位給段分配空間。當段中存在的區滿了,Oracle為該段分配另外的區。由於區是按需分配的,一個段的區可能是也可能不是連續的。 

  段和它的所有區儲存在一個資料表空間中。在一個資料表空間中,一個段包括的區能分布在多個檔案中,也即段能跨越資料檔案。無論如何,每個區必須在一個資料檔案中。

相關文章

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.