開(kāi)始-運(yùn)行-輸入“cmd”-輸入exp user/password@IP地址:1521/數(shù)據(jù)庫(kù)實(shí)例 file=文件所在目錄

創(chuàng)新互聯(lián)主要從事網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)博州,十年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來(lái)電咨詢建站服務(wù):028-86922220
(如:exp user/password@192.168.141.40:1521/orcl file=E:\work\dmp\person.dmp)
Oracle數(shù)據(jù)導(dǎo)入導(dǎo)出imp/exp
功能:Oracle數(shù)據(jù)導(dǎo)入導(dǎo)出imp/exp就相當(dāng)與oracle數(shù)據(jù)還原與備份。
大多情況都可以用Oracle數(shù)據(jù)導(dǎo)入導(dǎo)出完成數(shù)據(jù)的備份和還原(不會(huì)造成數(shù)據(jù)的丟失)。
Oracle有個(gè)好處,雖然你的電腦不是服務(wù)器,但是你裝了oracle客戶端,并建立了連接
(通過(guò)Net Configuration Assistant添加正確的服務(wù)命名,其實(shí)你可以想成是客戶端與服務(wù)器端 修了條路,然后數(shù)據(jù)就可以被拉過(guò)來(lái)了)
這樣你可以把數(shù)據(jù)導(dǎo)出到本地,雖然可能服務(wù)器離你很遠(yuǎn)。
你同樣可以把dmp文件從本地導(dǎo)入到遠(yuǎn)處的數(shù)據(jù)庫(kù)服務(wù)器中。
利用這個(gè)功能你可以構(gòu)建倆個(gè)相同的數(shù)據(jù)庫(kù),一個(gè)用來(lái)測(cè)試,一個(gè)用來(lái)正式使用。
執(zhí)行環(huán)境:可以在SQLPLUS.EXE或者DOS(命令行)中執(zhí)行,
DOS中可以執(zhí)行時(shí)由于 在oracle 8i 中 安裝目錄\$ora10g\BIN被設(shè)置為全局路徑,
該目錄下有EXP.EXE與IMP.EXE文件被用來(lái)執(zhí)行導(dǎo)入導(dǎo)出。
oracle用java編寫,我想SQLPLUS.EXE、EXP.EXE、IMP.EXE這倆個(gè)文件是被包裝后的類文件。
SQLPLUS.EXE調(diào)用EXP.EXE、IMP.EXE他們所包裹的類,完成導(dǎo)入導(dǎo)出功能。
下面介紹的是導(dǎo)入導(dǎo)出的實(shí)例,向?qū)雽?dǎo)出看實(shí)例基本上就可以完成,因?yàn)閷?dǎo)入導(dǎo)出很簡(jiǎn)單。
數(shù)據(jù)導(dǎo)出:
1 將數(shù)據(jù)庫(kù)TEST完全導(dǎo)出,用戶名system 密碼manager 導(dǎo)出到D:\daochu.dmp中
exp system/manager@TEST file=d:\daochu.dmp full=y
2 將數(shù)據(jù)庫(kù)中system用戶與sys用戶的表導(dǎo)出
exp system/manager@TEST file=d:\daochu.dmp owner=(system,sys)
3 將數(shù)據(jù)庫(kù)中的表table1 、table2導(dǎo)出
exp system/manager@TEST file=d:\daochu.dmp tables=(table1,table2)
4 將數(shù)據(jù)庫(kù)中的表table1中的字段filed1以"00"打頭的數(shù)據(jù)導(dǎo)出
exp system/manager@TEST file=d:\daochu.dmp tables=(table1) query=\" where filed1 like '00%'\"
上面是常用的導(dǎo)出,對(duì)于壓縮我不太在意,用winzip把dmp文件可以很好的壓縮。
不過(guò)在上面命令后面 加上 compress=y 就可以了
數(shù)據(jù)的導(dǎo)入
1 將D:\daochu.dmp 中的數(shù)據(jù)導(dǎo)入 TEST數(shù)據(jù)庫(kù)中。
imp system/manager@TEST file=d:\daochu.dmp
上面可能有點(diǎn)問(wèn)題,因?yàn)橛械谋硪呀?jīng)存在,然后它就報(bào)錯(cuò),對(duì)該表就不進(jìn)行導(dǎo)入。
在后面加上 ignore=y 就可以了。
2 將d:\daochu.dmp中的表table1 導(dǎo)入
imp system/manager@TEST file=d:\daochu.dmp tables=(table1)
基本上上面的導(dǎo)入導(dǎo)出夠用了。不少情況我是將表徹底刪除,然后導(dǎo)入。
注意:
你要有足夠的權(quán)限,權(quán)限不夠它會(huì)提示你。
數(shù)據(jù)庫(kù)時(shí)可以連上的。可以用tnsping TEST 來(lái)獲得數(shù)據(jù)庫(kù)TEST能否連上。
數(shù)據(jù)導(dǎo)出:
exp hkb/hkb@boss_14 full=y file=c:\orabackup\hkbfull.dmp log=c:\orabackup\hkbfull.log;
導(dǎo)出注意事項(xiàng):導(dǎo)出的是當(dāng)前用戶的的數(shù)據(jù),當(dāng)前用戶如果有DBA的權(quán)限,則導(dǎo)出所有數(shù)據(jù)!
同名用戶之間的數(shù)據(jù)導(dǎo)入:
imp hkb/hkb@xe file=c:\orabackup\hkbfull.dmp log=c:\orabackup\hkbimp.log full=y
不同名之間的數(shù)據(jù)導(dǎo)入:
imp system/test@xe fromuser=hkb touser=hkb_new file=c:\orabackup\hkbfull.dmp
log=c:\orabackup\hkbimp.log;
1 將數(shù)據(jù)庫(kù)TEST完全導(dǎo)出,用戶名system 密碼manager 導(dǎo)出到D:\daochu.dmp中\(zhòng)x0d\x0a exp system/manager@TEST file=d:\daochu.dmp full=y\x0d\x0a2 將數(shù)據(jù)庫(kù)中system用戶與sys用戶的表導(dǎo)出\x0d\x0a exp system/manager@TEST file=d:\daochu.dmp owner=(system,sys)\x0d\x0a3 將數(shù)據(jù)庫(kù)中的表table1 、table2導(dǎo)出\x0d\x0a exp system/manager@TEST file=d:\daochu.dmp tables=(table1,table2) \x0d\x0a4 將數(shù)據(jù)庫(kù)中的表table1中的字段filed1以"00"打頭的數(shù)據(jù)導(dǎo)出\x0d\x0a exp system/manager@TEST file=d:\daochu.dmp tables=(table1) query=\" where filed1 like '00%'\"\x0d\x0a \x0d\x0a 上面是常用的導(dǎo)出,對(duì)于壓縮我不太在意,用winzip把dmp文件可以很好的壓縮。\x0d\x0a 不過(guò)在上面命令后面 加上 compress=y 就可以了
1 將數(shù)據(jù)庫(kù)TEST完全導(dǎo)出,用戶名system 密碼manager 導(dǎo)出到D:\daochu.dmp中
exp system/manager@TEST file=d:\daochu.dmp full=y
2 將數(shù)據(jù)庫(kù)中system用戶與sys用戶的表導(dǎo)出
exp system/manager@TEST file=d:\daochu.dmp owner=(system,sys)
3 將數(shù)據(jù)庫(kù)中的表table1 、table2導(dǎo)出
exp system/manager@TEST file=d:\daochu.dmp tables=(table1,table2)
4 將數(shù)據(jù)庫(kù)中的表table1中的字段filed1以"00"打頭的數(shù)據(jù)導(dǎo)出
exp system/manager@TEST file=d:\daochu.dmp tables=(table1) query=\" where filed1 like '00%'\"
Oracle導(dǎo)出導(dǎo)出有兩中方式:一、利用exp imp導(dǎo)出導(dǎo)入;二、利用Oracel數(shù)據(jù)泵expdp impdp導(dǎo)出導(dǎo)入。
一、利用exp imp導(dǎo)出導(dǎo)入
exp imp 語(yǔ)法如下:
exp:
1) 將數(shù)據(jù)庫(kù)orcl完全導(dǎo)出
exp system/manager@orcl file=d:\orcl_bak.dmp full=y
2) 將數(shù)據(jù)庫(kù)中system用戶的表導(dǎo)出
exp system/manager@orcl file=d:\system_bak.dmp owner=system
3) 將數(shù)據(jù)庫(kù)中表table1,table2導(dǎo)出
exp system/manager@orcl file=d:\table_bak.dmp tables=(table1,table2)
4) 將數(shù)據(jù)庫(kù)中的表customer中的字段mobile以"139"開(kāi)頭的數(shù)據(jù)導(dǎo)出
exp system/manager@orcl file=d:\mobile_bak.dmp tables=customer query=\"where mobile like '139%' \"
imp:
1) 將備份文件bak.dmp導(dǎo)出數(shù)據(jù)庫(kù)
imp system/manager@orcl file=d:\bak.dmp
如果數(shù)據(jù)表中表已經(jīng)存在,會(huì)提示錯(cuò)誤,在后面加上ignore=y就可以了。
2) 將備份文件bak.dmp中的表table1導(dǎo)入
imp system/manager@orcl file=d:\bak.dmp tables=(table1)
exp imp導(dǎo)出導(dǎo)入數(shù)據(jù)方式的好處是只要你本地安裝了Oracle客戶端,你就可以將服務(wù)器中的數(shù)據(jù)導(dǎo)出到你本地計(jì)算機(jī)。同樣也可以將dmp文件從你本地導(dǎo)入到服務(wù)器數(shù)據(jù)庫(kù)中。但是這種方式在Oracle11g版本中會(huì)出現(xiàn)一個(gè)問(wèn)題:不能導(dǎo)出空表。Oracle11g新增了一個(gè)參數(shù)deferred_segment_creation,含義是段延遲創(chuàng)建,默認(rèn)是true。當(dāng)你新建了一張表,并且沒(méi)用向其中插入數(shù)據(jù)時(shí),這個(gè)表不會(huì)立即分配segment。
解決辦法:
1、設(shè)置deferred_segment_creation參數(shù)為false后,無(wú)論是空表,還是非空表,都分配segment。
在sqlplus中,執(zhí)行如下命令:
SQLalter system set deferred_segment_creation=false;
查看:
SQLshow parameter deferred_segment_creation;
該值設(shè)置后,只對(duì)后面新增的表起作用,對(duì)之前建立的空表不起作用,并且注意要重啟數(shù)據(jù)庫(kù)讓參數(shù)生效。
2、使用 ALLOCATE EXTEN
使用 ALLOCATE EXTEN可以為數(shù)據(jù)庫(kù)對(duì)象分配Extent,語(yǔ)法如下:
alter table table_name allocate extent
構(gòu)建對(duì)空表分配空間的SQL命令:
SQLselect 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0
批量生成要修改的語(yǔ)句。
然后執(zhí)行這些修改語(yǔ)句,對(duì)所有空表分配空間。
此時(shí)用exp命令,可將包括空表在內(nèi)的所有表導(dǎo)出。
二、利用expdp impdp導(dǎo)出導(dǎo)入
在Oracle10g中exp imp被重新設(shè)計(jì)為Oracle Data Pump(保留了原有的 exp imp工具)
數(shù)據(jù)泵與傳統(tǒng)導(dǎo)出導(dǎo)入的區(qū)別;
1) exp和imp是客戶端工具,他們既可以在客戶端使用,也可以在服務(wù)端使用。
2) expdp和impdp是服務(wù)端工具,只能在Oracle服務(wù)端使用。
3) imp只適用于exp導(dǎo)出文件,impdp只適用于expdp導(dǎo)出文件。
expdp導(dǎo)出數(shù)據(jù):
1、為輸出路徑建立一個(gè)數(shù)據(jù)庫(kù)的directory對(duì)象。
create or replace directory dumpdir as 'd:\';
可以通過(guò):select * from dba_directories;查看。
2、給將要進(jìn)行數(shù)據(jù)導(dǎo)出的用戶授權(quán)訪問(wèn)。
grant read,write on directory dumpdir to test_expdp;
3、將數(shù)據(jù)導(dǎo)出
expdp test_expdp/test_expdp directory=dumpdir dumpfile=test_expdp_bak.dmp logfile=test_expdp_bak.log schemas=test_expdp
注意:這句話在cmd窗口中運(yùn)行,并且最后不要加分號(hào),否則會(huì)提示錯(cuò)誤。因?yàn)檫@句話是操作系統(tǒng)命令而不是SQL。
impdp導(dǎo)入數(shù)據(jù):
1、給將要進(jìn)行數(shù)據(jù)導(dǎo)入的用戶授權(quán)訪問(wèn)。
grant read,write on directory dumpdir to test_impdp;
2、將數(shù)據(jù)導(dǎo)入
impdp test_impdp/impdp directory=dumpdir dumpfile=test_expdp_bak.dmp remap_schema=test_expdp:test_impdp
1、首先通過(guò)tode創(chuàng)建或者克隆新的數(shù)據(jù)庫(kù)用戶,如下圖所示。
2、導(dǎo)出目標(biāo)表準(zhǔn)備好,空表無(wú)法導(dǎo)出表結(jié)構(gòu),然后打開(kāi)運(yùn)行命令,導(dǎo)出目標(biāo)用戶test所有數(shù)據(jù)庫(kù)相關(guān)信息,如下圖所示。
3、輸入完成后,點(diǎn)擊鍵盤上的回車,等待一會(huì)如下圖所示。
4、最后導(dǎo)入目標(biāo)用戶new所有數(shù)據(jù)庫(kù)相關(guān)信息,如下圖所示。
5、最后如下圖所示,就導(dǎo)出完成了。
本文名稱:oracle如何將庫(kù)導(dǎo)出,oracle數(shù)據(jù)庫(kù)導(dǎo)出導(dǎo)入
文章起源:http://www.chinadenli.net/article12/heohgc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名、定制開(kāi)發(fā)、網(wǎng)站內(nèi)鏈、小程序開(kāi)發(fā)、網(wǎng)站策劃、網(wǎng)站制作
聲明:本網(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í)需注明來(lái)源: 創(chuàng)新互聯(lián)