(轉)oracle使用expdp、impdp和exp、imp導入導出表及表結構


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

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

exp、imp導入導出


sqlplus 進入數據庫中 
導出 
直接在命令行下寫命令 
1.導出自己的表   
exp userid=scott/tiger@myoral tables=(emp,dept) file=/opt/e1.dmp 
  
2.導出其它方案的表 如果用戶要導出其它方案的表,則需要dba的權限或是exp_full_database的權限,比如system就可以導出scott的表   
exp userid=system/manager@myoral tables=(scott.emp) file=d:\e2.emp  
3. 導出表的結構   
exp userid=scott/tiger@accp tables=(emp) file=/opt/e3.dmp rows=n  
4. 使用直接導出方式  
exp userid=scott/tiger@accp tables=(emp) file=/opt/e4.dmp direct=y  
這種方式比默認的常規方式速度要快,當數據量大時,可以考慮使用這樣的方法。 這時需要數據庫的字符集要與客戶端字符集完全一致,否則會報錯 
導出方案 導出方案是指使用export工具導出一個方案或是多個方案中的所有對象(表,索引,約束...)和數據。並存放到文件中 
1. 導出自己的方案  
exp userid=scott/tiger@myorcl owner=scott file=/opt/scott.dmp  
2. 導出其它方案 如果用戶要導出其它方案,則需要dba的權限或是exp_full_database的權限,比如system用戶可以導出任何方案  
exp userid=system/manager@myorcl owner=(system,scott) file=/opt/system.dmp  
導出數據庫  
導出數據庫是指利用export導出所有數據庫中的對象及數據,要求該用戶具有dba的權限或者是exp_full_database權限 增量備份(好處是第一次備份后,第二次備份就快很多了) 
 exp userid=system/manager@myorcl full=y inctype=complete file=/opt/all.dmp 
導入  
1. 導入自己的表  
imp userid=scott/tiger@myorcl tables=(emp) file=/opt/xx.dmp  
2. 導入表到其它用戶 要求該用戶具有dba的權限 
imp_full_database imp userid=system/tiger@myorcl tables=(emp) file=/opt/xx.dmp touser=scott
 3. 導入表的結構,只導入表的結構而不導入數據  
imp userid=scott/tiger@myorcl tables=(emp) file=/opt/xx.dmp rows=n 
4. 導入數據 如果對象(如比表)已經存在可以只導入表的數據 
imp userid=scott/tiger@myorcl tables=(emp) file=/opt/xx.dmp ignore=y 
導入方案 導入方案是指使用import工具將文件中的對象和數據導入到一個或是多個方案中。如果要導入其它方案,要求該用戶具有dba的權限,或者imp_full_database
 1. 導入自身的方案 
imp userid=scott/tiger file=/opt/xxx.dmp  
2. 導入其它方案 要求該用戶具有dba的權限  
imp userid=system/manager file=/opt/xxx.dmp fromuser=system touser=scott 
導入數據庫  
在默認情況下,當導入數據庫時,會導入所有對象結構和數據,案例如下:  
imp userid=system/manager full=y file=/opt/xxx.dmp 

expdp、impdp導入導出


一、准備工作

1)、在備份目的路徑建立備份文件夾 
例如:d:\bak

2)、用sys用戶在oracle中創建邏輯目錄 
SQL>create directory oracleBak_dir as ‘d:\bak’;

3)、查看數據庫中的邏輯目錄 
SQL>select * from dba_directories;

4)、授權用戶有對邏輯目錄的讀寫權限 
SQL>grant read,write on directory oracleBak_dir to someone;

二、導出

1)導出用戶 
expdp scott/tiger@orcl schemas=scott dumpfile=expdp.dmp directory=oracleBak_dir ;

2)導出表 
expdp scott/tiger@orcl tables=emp,dept dumpfile=expdp.dmp directory=oracleBak_dir ;

3)按查詢條件導 
expdp scott/tiger@orcl directory=oracleBak_dir dumpfile=expdp.dmp tables=emp query=’where deptno=20’;

4)按表空間導 
expdp system/manager@orcl directory=oracleBak_dir dumpfile=tablespace.dmp tablespaces=temp,example;

5)導整個數據庫 
expdp system/manager@orcl directory=oracleBak_dir dumpfile=full.dmp full=y;

三、導入數據

1)導入用戶(從用戶scott導入到用戶scott) 
impdp scott/tiger@orcl directory=oracleBak_dir dumpfile=expdp.dmp schemas=scott;

2)導入表(從scott用戶中把表dept和emp導入到system用戶中) 
impdp system/manager@orcl directory=oracleBak_dir dumpfile=expdp.dmp tables=scott.dept,scott.emp remap_schema=scott:system;

3)導入表空間 
impdp system/manager@orcl directory=oracleBak_dir dumpfile=tablespace.dmp tablespaces=example;

4)導入數據庫 
impdb system/manager@orcl directory=oracleBak_dir dumpfile=full.dmp full=y;

5)追加數據 
impdp system/manager@orcl directory=dump_dir dumpfile=expdp.dmp schemas=systemtable_exists_action

參考文檔: 
http://docs.oracle.com/cd/B19306_01/server.102/b14215/dp_export.htm#i1007509

http://docs.oracle.com/cd/B19306_01/server.102/b14215/dp_import.htm#g1025464


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM