一非驮、新建邏輯目錄
最好以system等管理員創(chuàng)建邏輯目錄睦授,Oracle不會自動創(chuàng)建實際的物理目錄“D:\oracleData”(務(wù)必手動創(chuàng)建此目錄),僅僅是進行定義邏輯路徑dump_dir侠姑;
? ? ?sql>?conn system/123456a?@orcl as sysdba;
? ? ?sql>create directory dump_dir as 'D:\oracleData';
二介评、查看管理員目錄(同時查看操作系統(tǒng)是否存在該目錄卜壕,因為oracle并不關(guān)心該目錄是否存在廉羔,假如不存在瞄勾,則出錯)
? ? ?sql>select * from dba_directories;
三糊昙、用expdp導(dǎo)出數(shù)據(jù)
1)導(dǎo)出用戶及其對象
expdp scott/tiger@orcl schemas=scott dumpfile=expdp.dmp directory=dump_dir;
2)導(dǎo)出指定表
expdp scott/tiger@orcl tables=emp,dept dumpfile=expdp.dmp directory=dump_dir;
3)按查詢條件導(dǎo)
expdp scott/tiger@orcl directory=dump_dir dumpfile=expdp.dmp tables=empquery='where deptno=20';
4)按表空間導(dǎo)
expdp system/manager@orcl directory=dump_dir dumpfile=tablespace.dmptablespaces=temp,example;
5)導(dǎo)整個數(shù)據(jù)庫
expdp system/manager@orcl directory=dump_dir dumpfile=full.dmp full=y;
四辛掠、用impdp導(dǎo)入數(shù)據(jù)
? ?在正式導(dǎo)入數(shù)據(jù)前,要先確保要導(dǎo)入的用戶已存在释牺,如果沒有存在萝衩,請先用下述命令進行新建用戶
--創(chuàng)建表空間
create tablespace tb_name datafile 'D:\tablespace\tb_name.dbf' size 1024m AUTOEXTEND ON;
--創(chuàng)建用戶
create user user_name identified by A123456a default tablespace tb_name?temporary tablespace TEMP;
--給用戶授權(quán)
sql>grant read,write on directory dump_dir?to user_name;
sql>grant dba,resource,unlimited tablespace to user_name;
1)導(dǎo)入用戶(從用戶scott導(dǎo)入到用戶scott)
impdp scott/tiger@orcl directory=dump_dir dumpfile=expdp.dmp schemas=scott;
2)導(dǎo)入表(從scott用戶中把表dept和emp導(dǎo)入到system用戶中)
impdp system/manager@orcl directory=dump_dir dumpfile=expdp.dmptables=scott.dept,scott.emp remap_schema=scott:system;
3)導(dǎo)入表空間
impdp system/manager@orcl directory=dump_dir dumpfile=tablespace.dmp tablespaces=example;
4)導(dǎo)入數(shù)據(jù)庫
impdb system/manager@orcl directory=dump_dir dumpfile=full.dmp full=y;
5)追加數(shù)據(jù)
impdp system/manager@orcl directory=dump_dir dumpfile=expdp.dmp schemas=systemtable_exists_action