Oracle 數據泵(IMPDP/EXPDP)導入導出總結
Oracle數據泵導入導出是日常工作中常用的基本技術之一,它相對傳統的邏輯導入導出要高效,這種特性更適合數據庫對象數量巨大的情形,因為我日常運維的數據庫對象少則幾千,多則幾萬甚至幾十萬,所以傳統exp/imp就會非常耗時,而數據泵方式就因此脫引而出,下面就詳細總結一下數據泵的使用方法,希望能給初學者帶來幫助。
一、新建邏輯目錄
最好以system等管理員創建邏輯目錄,Oracle不會自動創建實際的物理目錄“D:\oracleData”(務必手動創建此目錄),僅僅是進行定義邏輯路徑dump_dir;
sql> conn system/123456a?@orcl as sysdba;
sql>create directory dump_dir as 'D:\oracleData';
二、查看管理員目錄(同時查看操作系統是否存在該目錄,因為oracle並不關心該目錄是否存在,假如不存在,則出錯)
sql>select * from dba_directories;
三、用expdp導出數據
1)導出用戶及其對象
expdp scott/tiger@orcl schemas=scott dumpfile=expdp.dmp directory=dump_dir;
2)導出指定表
expdp scott/tiger@orcl tables=emp,dept dumpfile=expdp.dmp directory=dump_dir;
3)按查詢條件導
expdp scott/tiger@orcl directory=dump_dir dumpfile=expdp.dmp tables=empquery='where deptno=20';
4)按表空間導
expdp system/manager@orcl directory=dump_dir dumpfile=tablespace.dmptablespaces=temp,example;
5)導整個數據庫
expdp system/manager@orcl directory=dump_dir dumpfile=full.dmp full=y;
四、用impdp導入數據
在正式導入數據前,要先確保要導入的用戶已存在,如果沒有存在,請先用下述命令進行新建用戶
--創建表空間
create tablespace tb_name datafile 'D:\tablespace\tb_name.dbf' size 1024m AUTOEXTEND ON;
--創建用戶
create user user_name identified by A123456a default tablespace tb_name temporary tablespace TEMP;
--給用戶授權
sql>grant read,write on directory dump_dir to user_name;
sql>grant dba,resource,unlimited tablespace to user_name;
1)導入用戶(從用戶scott導入到用戶scott)
impdp scott/tiger@orcl directory=dump_dir dumpfile=expdp.dmp schemas=scott;
2)導入表(從scott用戶中把表dept和emp導入到system用戶中)
impdp system/manager@orcl directory=dump_dir dumpfile=expdp.dmptables=scott.dept,scott.emp remap_schema=scott:system;
3)導入表空間
impdp system/manager@orcl directory=dump_dir dumpfile=tablespace.dmp tablespaces=example;
4)導入數據庫
impdb system/manager@orcl directory=dump_dir dumpfile=full.dmp full=y;
5)追加數據
impdp system/manager@orcl directory=dump_dir dumpfile=expdp.dmp schemas=systemtable_exists_action
以上是日常工作中實際工作中用到的,希望能夠給你得到幫助。