1. 程式人生 > >oracle建立表空間,建立使用者,匯入dmp資料

oracle建立表空間,建立使用者,匯入dmp資料

匯入oracle資料的時候,經常到用的時候忘記,特整理一份,方便以後操作。

需要注意的是:建立表空間和使用者是在sqlPlus中執行,而匯入資料需要在cmd視窗執行。

一、建立表空間

create tablespace 表空間名 datafile 'd:/*.dbf' size *M
在建立的時候定義表空間名,表空間檔案對應的位置及大小,我一般都是設定為100M,根據個人情況來設定

附:刪除表空間

drop tablespace 表空間名 including contents and datafiles 

二、建立使用者並賦許可權

1.建立使用者

create user 使用者名稱 identified by 密碼 default tablespace 預設表空間名

    2.1 預設的普通使用者scott預設未解鎖,不能進行那個使用,新建的使用者也沒有任何許可權,必須授予許可權

grant create session to zhangsan;//授予zhangsan使用者建立session的許可權,即登陸許可權

grant unlimited tablespace to zhangsan;//授予zhangsan使用者使用表空間的許可權

grant create table to zhangsan;//授予建立表的許可權

grante drop table to zhangsan;//授予刪除表的許可權

grant insert table to zhangsan;//插入表的許可權

grant update table to zhangsan;//修改表的許可權

grant all to public;//這條比較重要,授予所有許可權(all)給所有使用者(public)

    2.2 oralce對許可權管理比較嚴謹,普通使用者之間也是預設不能互相訪問的,需要互相授權

grant select on tablename to zhangsan;//授予zhangsan使用者檢視指定表的許可權

grant drop on tablename to zhangsan;//授予刪除表的許可權

grant insert on tablename to zhangsan;//授予插入的許可權

grant update on tablename to zhangsan;//授予修改表的許可權

grant insert(id) on tablename to zhangsan;

grant update(id) on tablename to zhangsan;//授予對指定表特定欄位的插入和修改許可權,注意,只能是insert和update

grant alert all table to zhangsan;//授予zhangsan使用者alert任意表的許可權

3.賦予dba許可權(可選)

grant dba to 使用者;
因為我選擇匯入的資料是由dba使用者匯出的,需要dba許可權的使用者才能匯入。

三、匯入資料

imp 使用者名稱/密碼@orcl file=d:/資料名.dmp full=y ignore=y  log=d:/匯出日誌.log
附:匯出資料

    1.匯出本機資料

exp 使用者名稱/密碼@orcl file=d:/匯出檔名.dmp full=y log=d:/匯出日誌.log
    2.匯出遠端資料
exp 使用者名稱/密碼@ip地址:1521/orcl file=d:/匯出檔名.dmp full=y log=d:/匯出日誌.log