Oracle 利用數據泵導入導出數據

目的:使用數據泵,將一臺電腦上的數據庫導出,導入到另一臺電腦上的數據庫。

A電腦上的操作。expdp數據導出

1、運行cmd;

2、登錄數據庫,輸入命令:

sqlplus system/密碼;

3、創建目錄路徑:

create directory backup_path as ‘E:\app\tws\oradata\orcldv’;  

(backup_path爲路徑名稱,可自命名(必須是已存在路徑),E:\app\tws\oradata\orcl爲源數據庫路徑)

5、導入導出操作授權:

grant exp_full_database,imp_full_database to dmuser;  (dmuser爲數據庫用戶名)

6、退出:exit;

7、數據導出,執行命令:

expdp  dmuser/***** directory=backup_path dumpfile=dmuser_schema.dmp logfile=dmuser_schema_29.log;

dmuser爲用戶名
*****爲密碼
dmuser_schema.dmp爲導出數據庫文件,可自命名,但格式要爲.dmp,dmuser_schema_29.log爲日誌文件,可自命名


B電腦上的操作。impdp 數據導入

將導出的數據庫文件複製到目標數據庫路徑下。

1、運行cmd;

2、登錄數據庫,輸入命令:

sqlplus system/密碼;

3、創建目錄路徑:

create directory goup_path as ‘E:\app\tws\oradata\orcl’;   

(goup_path爲路徑名稱,可自命名,E:\app\tws\oradata\orcl爲目標數據庫路徑)

4、退出:exit;

5、數據導入,執行命令:

impdp  dmuser/*****  directory=goup_path  dumpfile=dmuser_schema.dmp  logfile=dmuser_schema_29.log;

完整演示

create directory backup_path as 'E:\XPAD';
grant exp_full_database,imp_full_database to xpad706;
expdp xpad706/xpad706 directory=backup_path dumpfile=xpad706.dmp logfile=xpad706.log;
impdp  xpad706/xpad706  directory=backup_path   dumpfile=xpad706.dmp  logfile=impxpad706.log;

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
以上是日常工作中實際工作中用到的,希望能夠給你得到幫助。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章