1. 程式人生 > >ORACLE使用EXPDP和IMPDP資料泵進行匯出匯入的方法

ORACLE使用EXPDP和IMPDP資料泵進行匯出匯入的方法

ORACLE使用EXPDP和IMPDP資料泵進行匯出匯入的方法

使用expdp和impdp時應該注重的事項:

1、exp和imp是客戶端工具程式,它們既可以在客戶端使用,也可以在服務端使用。
2、expdp和impdp是服務端的工具程式,他們只能在oracle服務端使用,不能在客戶端使用。
3、imp只適用於exp匯出的檔案,不適用於expdp匯出檔案;impdp只適用於expdp匯出的檔案,而不適用於exp匯出檔案。
4、對於10g以上的伺服器,使用exp通常不能匯出0行資料的空表,而此時必須使用expdp匯出。


一、建立邏輯目錄,該命令不會在作業系統建立真正的目錄(請先建立真正的目錄),最好以system等管理員建立邏輯目錄。
SQL>conn system/

[email protected] as sysdba
SQL>create directory dump_dir as 'd:\test\dump';

 

二、檢視管理員目錄(同時檢視作業系統是否存在,因為oracle並不關心該目錄是否存在,假如不存在,則出錯)
SQL>select * from dba_directories;

 

三、給scott使用者賦予在指定目錄的操作許可權,最好以system等管理員賦予。
SQL>grant read,write on directory dump_dir to scott;

 

四、用expdp匯出資料

1)匯出使用者
expdp scott/[email protected] schemas=scott dumpfile=expdp.dmp directory=dump_dir;

2)匯出表
expdp scott/[email protected] tables=emp,dept dumpfile=expdp.dmp directory=dump_dir;

3)按查詢條件導
expdp scott/[email protected] directory=dump_dir dumpfile=expdp.dmp tables=empquery='where deptno=20';

4)按表空間導
expdp system/[email protected] directory=dump_dir dumpfile=tablespace.dmptablespaces=temp,example;

5)導整個資料庫
expdp system/[email protected] directory=dump_dir dumpfile=full.dmp full=y;


五、用impdp匯入資料

1)匯入使用者(從使用者scott匯入到使用者scott)
impdp scott/[email protected] directory=dump_dir dumpfile=expdp.dmp schemas=scott;

2)匯入表(從scott使用者中把表dept和emp匯入到system使用者中)
impdp system/[email protected] directory=dump_dir dumpfile=expdp.dmptables=scott.dept,scott.emp remap_schema=scott:system;

3)匯入表空間
impdp system/[email protected] directory=dump_dir dumpfile=tablespace.dmp tablespaces=example;

4)匯入資料庫
impdb system/[email protected] directory=dump_dir dumpfile=full.dmp full=y;

5)追加資料
impdp system/[email protected] directory=dump_dir dumpfile=expdp.dmp schemas=systemtable_exists_action