數(shù)據(jù)泵EXPDP導(dǎo)出工具和IMPDP導(dǎo)入工具的使用

數(shù)據(jù)泵EXPDP導(dǎo)出工具和IMPDP導(dǎo)入工具的使用 

成都創(chuàng)新互聯(lián)是專業(yè)的察雅網(wǎng)站建設(shè)公司,察雅接單;提供網(wǎng)站建設(shè)、成都網(wǎng)站制作,網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行察雅網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!

一、EXPDP和IMPDP使用說明

Oracle Database 10g引入了最新的數(shù)據(jù)泵(Data Dump)技術(shù),數(shù)據(jù)泵導(dǎo)出導(dǎo)入(EXPDP和IMPDP)的作用

1)實(shí)現(xiàn)邏輯備份和邏輯恢復(fù)。

2)在數(shù)據(jù)庫用戶之間移動(dòng)對(duì)象。

3)在數(shù)據(jù)庫之間移動(dòng)對(duì)象。

4)實(shí)現(xiàn)表空間搬移。


二、數(shù)據(jù)泵導(dǎo)出導(dǎo)入與傳統(tǒng)導(dǎo)出導(dǎo)入的區(qū)別

在10g之前,傳統(tǒng)的導(dǎo)出和導(dǎo)入分別使用EXP工具和IMP工具,從10g開始,不僅保留了原有的EXP和IMP工具,還提供了數(shù)據(jù)泵導(dǎo)出導(dǎo)入工具EXPDP和IMPDP。使用EXPDP和IMPDP時(shí)應(yīng)該注意的事項(xiàng):

1)EXP和IMP是客戶端工具程序,它們既可以在可以客戶端使用,也可以在服務(wù)端使用。

2)EXPDP和IMPDP是服務(wù)端的工具程序,他們只能在ORACLE服務(wù)端使用,不能在客戶端使用。

3)IMP只適用于EXP導(dǎo)出文件,不適用于EXPDP導(dǎo)出文件;IMPDP只適用于EXPDP導(dǎo)出文件,而不適用于EXP導(dǎo)出文件。

4)數(shù)據(jù)泵導(dǎo)出包括按表導(dǎo)出,按用戶導(dǎo)出,按表空間導(dǎo)出,按數(shù)據(jù)庫導(dǎo)出4種方式。


三、EXPDP/IMPDP參數(shù)說明

可通過expdp/impdp help=y查看:

$ expdp help=y
$ impdp help=y

四、EXPDP實(shí)戰(zhàn)案例

使用EXPDP工具時(shí),其轉(zhuǎn)儲(chǔ)文件只能被存放在DIRECTORY對(duì)象對(duì)應(yīng)的OS目錄中,而不能直接指定轉(zhuǎn)儲(chǔ)文件所在的OS目錄.因此,使用EXPDP工具時(shí),必須首先建立DIRECTORY對(duì)象.并且需要為數(shù)據(jù)庫用戶授予使用DIRECTORY對(duì)象權(quán)限。

操作步驟如下:

a)命令行打開sqlplus

sqlplus /nolog
conn / as sysdba

b)創(chuàng)建邏輯目錄,該命令不會(huì)在操作系統(tǒng)創(chuàng)建真正的目錄(最好手工先建好),最好以administrator等管理員創(chuàng)建。

SQL>create directory dir as 'd:\dump'; --dir名稱可以隨便命名 需要手工創(chuàng)建d:\dump

c)查看管理理員目錄(同時(shí)查看操作系統(tǒng)中是否存在,因?yàn)镺racle并不關(guān)心該目錄是否存在,如果不存在,則出錯(cuò))

SQL>select * from dba_directories;

d)給scott用戶賦予在指定目錄的操作權(quán)限,最好以sys,system等管理員賦予。

SQL>grant read,write on directory dir to scott;

e)在unix下要注意directory目錄的讀寫權(quán)限問題。

更改directory目錄文件夾的權(quán)限:chown -R oracle:dba /dump_dir。

1)按表導(dǎo)出表

$ expdp scott/tiger directory=dump_dir DUMPFILE=dept.dmp TABLES=dept;

多表導(dǎo)出用逗號(hào)分隔:

$ expdp scott/tiger tables=emp,dept dumpfile=expdp.dmp directory=dump_dir;

 

2)按用戶導(dǎo)出

$ expdp scott/tiger directory=dump_dir dumpfile=schema.dmp logfile=schema.log schemas=system;

 

3)按表空間導(dǎo)出

$ expdp scott/tiger directory=dump_dir dumpfile=tb.dmp logfile=tb.log tablespaces=users

 

4)全庫導(dǎo)出

$ expdp system/manager directory=dump_dir dumpfile=full.dmp full=Y;
$ expdp scott/tiger directory=dump_dir dumpfile=full.dmp full=Y;

注:提示scott用戶沒有相應(yīng)的權(quán)限,給scott相應(yīng)的權(quán)限或使用system來做全庫導(dǎo)出 。

SQL> grant exp_full_database to scott;
Grant succeeded.

 

5)并行進(jìn)程parallel導(dǎo)出

$ expdp scott/tiger@orcl directory=dump_dir dumpfile=scott3.dmp parallel=40 job_name=scott3;

 

6)按查詢條件導(dǎo)

$ expdp scott/tiger directory=dump_dir dumpfile=expdp.dmp Tables=emp query='WHERE deptno=20';

 

六、IMPDP 實(shí)戰(zhàn)案例

1)按表導(dǎo)入

刪除用戶scott的emp表,在full.dmp中導(dǎo)入emp到用戶scott

$ impdp backup/backup1 directory=dump_dir dumpfile=full.dmp tables=scott.emp remap_schema=scott:scott

將scott.test表導(dǎo)入的SYSTEM用戶下

$ impdp backup/backup1 directory=dump_dir dumpfile=full.dmp tables=scott.test remap_schema=scott:system

注意,如果要將表導(dǎo)入到其他方案中,必須指定REMAP SCHEMA選項(xiàng)

 

2)導(dǎo)到指定用戶下

按用戶導(dǎo)入

impdp scott/tiger@orcl DIRECTORY=dump_dir DUMPFILE=expdp.dmp SCHEMAS=scott logfile=impdp.log;

導(dǎo)入時(shí)將scott用戶所屬對(duì)象轉(zhuǎn)換為system用戶

$ impdp system/manager DIRECTORY=dump_dir DUMPFILE=schema.dmp SCHEMAS=scott REMAP_SCHEMA=scott:system;

 

3)按表空間導(dǎo)入

$ impdp system/manager DIRECTORY=dump_dir DUMPFILE=tablespace.dmp TABLESPACES=user01

4)全庫導(dǎo)入

$ impdp system/manager DIRECTORY=dump_dir DUMPFILE=full.dmp FULL=y

5)expdp/impdp 不同用戶,不同表空間的使用

假設(shè)a用戶的默認(rèn)表空間是a,導(dǎo)出用戶a所有數(shù)據(jù):

SQL> conn / as sysdba
SQL> create directory dir as '/home/oracle/';
SQL> grant read,write on directory dir to system;

$ expdp system/oracle directory=dir dumpfile=data.dmp schemas=a logfile=data.log

impdp導(dǎo)入a用戶所有數(shù)據(jù)到b,并且轉(zhuǎn)換表空間a為b:

SQL> conn sys / as sysdba
SQL> create directory dir as '/home/oracle/';
SQL> grant read,write on directory dir to system;
$ impdp system/oracle directory=dir dumpfile=data.dmp remap_tablespace=a:b remap_schema=a:b logfile=data.log

解釋:

remap_schema=a:b 將數(shù)據(jù)的schema從a轉(zhuǎn)換為b

remap_tablespace=a:b 將數(shù)據(jù)的tablespace從a轉(zhuǎn)換為b

注意:

如果oracle是10g,要加參數(shù)EXCLUDE=TABLE_STATISTICS選項(xiàng)將table_statistics對(duì)象過濾。否則會(huì)出現(xiàn)數(shù)據(jù)泵導(dǎo)入中table_statistics長時(shí)間等待。

總結(jié):

執(zhí)行impdp時(shí)無需創(chuàng)建b用戶,在導(dǎo)入時(shí)會(huì)自動(dòng)創(chuàng)建并改名用戶a為b(擁有a的所有權(quán)限等),自動(dòng)設(shè)置默認(rèn)表空間為轉(zhuǎn)換后的表空間b。如果有多個(gè)表空間需要轉(zhuǎn)換,則使用多個(gè)remap_tablespace=源表空間:目標(biāo)表空間。此種方法只限于支持oracle10g以上版本。

 

6)在全庫備份文件中導(dǎo)入一張表到數(shù)據(jù)庫

$ impdp backup/backup1 directory=PUMP_DIR dumpfile=expdp.dmp include=table:\"=\'T1\'\"  logfile=impdp.log table_exists_action=replace;

 

7)在全庫備份文件中導(dǎo)入一張表并轉(zhuǎn)換表空間和owner

$impdp backup/backup1 directory=dump_dir dumpfile=expdp.dmp tables=t1 REMAP_TABLESPACE=DATA:USERS remap_schema=scott:system table_exists_action=replace;

 

8)通過dblink遠(yuǎn)程導(dǎo)入

$ impdp system/admin directory=mydir network_link=dblink16_zk schemas=lgb_zk remap_schema=lgb_zk:lgb_zk logfile=lgbzk1018.log PARALLEL=2

 

9)通過dblink指定參數(shù)文件遠(yuǎn)程導(dǎo)入

參數(shù)說明

NETWORK_LINK=dblink

schemas=源用戶

remap_schema=源用戶:目標(biāo)用戶

PARALLEL=2

EXCLUDE=TABLE:"IN('A','B','C','D')"  排除的表

通過參數(shù)文件遠(yuǎn)程導(dǎo)入

vim mypar.par
network_link=dblink16
schemas=zs2new
remap_schema=zs2new:zs2new
EXCLUDE=TABLE:"IN('A','B','C','D')"
PARALLEL=2
$ impdp system/admin directory=mydir parfile=h:\dump\mypar.par;

 

 

網(wǎng)站標(biāo)題:數(shù)據(jù)泵EXPDP導(dǎo)出工具和IMPDP導(dǎo)入工具的使用
文章起源:http://muchs.cn/article2/ihsiic.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、網(wǎng)站改版手機(jī)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)公司、網(wǎng)站收錄營銷型網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營