標籤:Oracle 資料泵 impdp expdp 張晨晨
前言:努力的人最後一定不會太差!!關注部落格或者加Q:1445696451一起努力!
~~~~~~~~分割~~~~~~~~~
一、簡介
1、邏輯備份:是建立資料庫物件的邏輯副本,並存入一個二進位轉儲檔案的過程。邏輯備份和邏輯恢複從本質上來講,就是資料的匯出和匯入。
2、資料泵:是一中在資料庫之間或者在資料庫網域作業系統之間高速傳輸資料的技術。可以把比作水流,那麼資料泵就像水泵一樣,可以將資料幫浦出來存到其他的位置。資料泵工具運行與伺服器之上,資料庫管理員需要指定資料庫操作目錄用來儲存這些轉儲的位元據。
二、操作
1、建立實體儲存體目錄
mkdir -p /opt/datapump
chown -R oracle:oinstall /opt/datapump
chmod -R 775 /opt/datapump
2、建立操作目錄
conn sys/123456 as sysdba
create directory dump_dir as ‘/opt/datapump/’;
3、授權scott對dump_dir可讀、可寫
grant read,write on directory dump_dir to scott;
4、建立測試使用者
create user zhangsan identified by 123456;
grant connect,resource to zhangsan;
grant read,write on directory dump_dir to zhangsan;
5、操作部分
文法格式
impdp/expdp user/password directory=operating_directory_name
dumpfile=dumpfile_name tables/schemas/tablespaces/full
注釋:
impdp :匯入
expdp :匯出
directory=operating_directory_name :指定操作目錄
dumpfile=dumpfile_name :指定轉儲檔案
tables :動作表
schemas :操作使用者
tablespaces :動作表空間
full :操作全部/整個資料庫
##還有其他很多參數,不詳細解釋了,只列出這幾個最常用的
1)將使用者的表匯出/匯出(備份/恢複)
expdp scott/tiger directory=dump_dir dumpfile=scott_emp.dmp tables=emp;
:匯出scott的emp表命名為 scott_emp.dmp
impdp scott/tiger directory=dump_dir dumpfile=scott_emp.dmp tables=emp;
:將scott_emp.dmp中的emp 資訊匯入到scott下
2)將使用者的表導給其他使用者
impdp system/123456 directory=dump_dir dumpfile=scott_emp.dmp
tables=scott.emp remap_schema=scott:zhangsan;
:將scott的emp表通過資料泵 導給zhangsan。這時候的操作需 要使用具有dba許可權的使用者進 行操作
3)匯出使用者模式(相當於使用者的屬性)
expdp scott/tiger directory=dump_dir dumpfile=scottschema.dmp schemas=scott;
:匯出使用者scott模式
impdp system/123456 directory=dump_dir dumpfile=scottschema.dmp
schemas=scott remap_schema=scott:zhangsan
:將scott的使用者模式導給 zhangsan;該操作可用於批量部 署Oracle使用者。假如說scott擁 有了一個許可權,那麼zhangsan 同樣獲得該許可權,某種情況可以 說相對於給zhangsan進行授權 操作,所以同樣的該操作需要 具有許可權才可以。
4)匯入匯出資料表空間
conn scott/tiger :串連到scott使用者
create tablespace qwe datafile ‘/opt/oracle/oradata/orcl/qwe1.dbf’ size 10M
autoextend on;
:在scott下建立一個資料表空間qwe, 大小10M,自動成長
expdp system/123456 directory=dump_dir dumpfile=scott_qwe.dmp
tablespaces=scott
:匯出scott的資料表空間qwe
impdp system/123456 directory=dump_dir dumpfile=scott_qwe.dmp
tablespaces=scott :匯入(就把expdp替換為impdp)
5)匯入匯出整個庫
expdp system/123456 directory=dump_dir dumpfile=orclfull.dmp full=y :匯出整個資料庫命名為 orclfull.dmp;在full=y的意思就 是備份整個庫。
impdp system/123456 directory=dump_dir dumpfile=orclfull.dmp full=y
:匯入整個資料庫(同樣是替換 expdp為impdp)
三、總結
1、想要通過資料泵進行匯入匯出操作首先要有一個資料庫操作目錄
2、必須對操作目錄具有讀取、寫入的許可權
3、如果需要匯入的資料會影響到其他使用者需要具有dba許可權
4、對錶空間、整個資料庫操作需要具有dba許可權
5、資料泵可以操作(匯入匯出)的對象有表、資料表空間、使用者模式、整個資料庫。
Oracle資料泵(Data Pump)