溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Oracle數(shù)據(jù)庫(kù)簡(jiǎn)介

發(fā)布時(shí)間:2020-06-23 20:39:08 來(lái)源:網(wǎng)絡(luò) 閱讀:623 作者:TaoismLi 欄目:關(guān)系型數(shù)據(jù)庫(kù)

一)基本概念介紹

在國(guó)內(nèi)有一款自主知識(shí)產(chǎn)權(quán)關(guān)系型數(shù)據(jù)庫(kù)(達(dá)夢(mèng)),其基本原理及管理方式與Oracle及其相似,因此涉及到的主要基本概念及代表的意義也基本一樣,所以這里不再驁述,請(qǐng)參考另一篇關(guān)于達(dá)夢(mèng)數(shù)據(jù)庫(kù)介紹的文章《DM(達(dá)夢(mèng))數(shù)據(jù)庫(kù)簡(jiǎn)介》。


二)安裝Oracle

不管是Windows安裝還是Linux安裝,網(wǎng)上有大量的安裝配置教程,這里也不再細(xì)說(shuō)。這篇博文主要關(guān)注數(shù)據(jù)庫(kù)原理及基本使用,因此還是需要快速實(shí)例化一個(gè)Oracle數(shù)據(jù)庫(kù),這里簡(jiǎn)單介紹一下基于docker的安裝配置。

    a. 首先,確認(rèn)已經(jīng)安裝配置好docker,如果沒(méi)有,請(qǐng)參考《Centos 7.5安裝Docker》安裝配置;

    b. 在Docker中獲取Oracle鏡像信息;

        #docker search oracle        //在列表中選擇需要版本,如果需要數(shù)據(jù)持久化特性,建議選擇sath89/oracle-xe-xxx類(lèi)型版本

    c. 啟動(dòng)docker實(shí)例;

        #docker run -d -p 49160:22 -p 49161:1521 -v /hostfolder:/dockerfolder --name xe sauth89/oracle-xe-11g      //以sauth89/oracle-xe-11g為例

        1. -d參數(shù)表示后臺(tái)運(yùn)行容器;

        2. -p參數(shù)做端口映射,將docker的22和1521端口分別映射到宿主機(jī)的49160和49161;

        3. -v參數(shù)表示目錄映射,其結(jié)果就是存在于dockerfolder目錄的文件也會(huì)在宿主機(jī)相應(yīng)目錄存一份;

        4. --name參數(shù)指定容器服務(wù)名;

    d. 通過(guò)上面c步,就會(huì)創(chuàng)建一個(gè)Oracle數(shù)據(jù)庫(kù)實(shí)例,默認(rèn)連接信息如下:

        hostname: localhost(即宿主機(jī))

        port: 49161

        SID: xe

        service name: xe

        username: system

        password: oracle

    e. 圖形化功能連接數(shù)據(jù)庫(kù)

        Oracle數(shù)據(jù)庫(kù)簡(jiǎn)介


三)基本使用

I. 管理命令

    a. 查詢版本

        select banner from sys.v_$version;

        或

        select * from v$version;

    b. 查看數(shù)據(jù)庫(kù)名(實(shí)例名)及狀態(tài)

        select name from v$database;

        select status from v$instance;

    c. 查看系統(tǒng)所有用戶

        select * from all_users;

    d. 創(chuàng)建用戶并賦予其鏈接數(shù)據(jù)庫(kù)權(quán)限

        create user username identified by passwd;

        grant connect to username;

    e. 刪除用戶

        drop user username ;

    f. 查看當(dāng)前用戶角色

        select * from user_role_privs;

    g. 查看表空間及使用情況

        select * from v$tablespace;     //查看系統(tǒng)所有表空間

        select tablespace_name,sum(bytes)/1024/1024 from dba_data_files group by tablespace_name; //單位是M

    h. 創(chuàng)建表空間

        create tablespace test_tbsp datafile '/home/oracle/oradata/test_tbsp.dbf' size 100M;    //數(shù)據(jù)文件一定要單引號(hào)引起來(lái)

    i. 查看用默認(rèn)表空間

        select username,default_tablespace from dba_users;

    j. 修改用戶默認(rèn)表空間

        alter user user1 default tablespace test_tbsp;

    k. 開(kāi)啟表空間自動(dòng)擴(kuò)展、查看、關(guān)閉

        alter database datafile '/home/oracle/oradata/test_tbsp.dbf' autoextend on;    //開(kāi)啟

        select file_name,autoextensible,increment_by from dba_data_files where tablespace_name='TEST_TBSP';    //查看

        alter database datafile '/home/oracle/oradata/test_tbsp.dbf' autoextend off;    //關(guān)閉


II. 角色、用戶及權(quán)限管理

    a. 創(chuàng)建角色

        create role roleName; 

    b. 給角色授予權(quán)限

        grant 權(quán)限 to roleName:

    c. 將角色授予用戶

        grant roleName to userName;

     d. 查詢當(dāng)前用戶擁有角色

        select * from user_role_privs;

     e. 刪除角色

        drop role roleName;

關(guān)于角色注意:

    1. 當(dāng)給角色授予權(quán)限的時(shí)候,擁有此角色的用戶也同時(shí)增加了權(quán)限;

    2. 當(dāng)撤銷(xiāo)角色權(quán)限的時(shí)候,擁有此角色的用戶的對(duì)應(yīng)權(quán)限也被撤銷(xiāo);

    3. 當(dāng)角色被刪除,擁有此角色的用戶將喪失之前角色所有的所有權(quán)限。

    f. 授予用戶會(huì)話權(quán)限

        grant create session to userName;

    g. 授予用戶建表權(quán)限

        grant create table to userName;

    h. 授予用戶無(wú)限制使用表空間權(quán)限

        grant unlimited tablespace to userName;

    i. 授予權(quán)限及撤銷(xiāo)權(quán)限

        grant 權(quán)限 to userName;

        revoke 權(quán)限 from userName;

        grant select on mytab to userName

        grant update on mytab to userName

        grant delete on mytab to userName

        grant insert on mytab to userName

        revoke select on mytab from userName

        批量賦權(quán): https://www.cnblogs.com/abcwt112/p/5507917.html 

    j. 查看用戶擁有權(quán)限

        select * from user_sys_privs;

    k. 授予/撤銷(xiāo)其他用戶操作表的所有權(quán)限

        grant all on mytab to userName;

        revoke all on mytab from userName;

     l. 查詢其他用戶對(duì)當(dāng)前用戶表的操作權(quán)限

        select * from user_tab_privs;

     m. 權(quán)限傳遞

        grant create session to userName with admin option;    //表示把系統(tǒng)權(quán)限授予給userName,并允許其授予給其他用戶

        grant update on mytab to userName with grant option;    //表示把操作表的權(quán)限授予給userName,并允許其授予給其他用戶

        

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI