利用外部命令Oralce数据库导入导出
?
1--數(shù)據(jù)庫導(dǎo)出(exp)?
?
首先進(jìn)入命令行?
?
導(dǎo)出數(shù)據(jù)庫?
?
在命令行中輸入如下命令:?
?
?
exp ? c2j/c2j@c2j ??
file=c:/table.dmp ??
tables=jbitaku,jbitakum ?
grants=y
?
?
然后按回車鍵?
?
說明: ?
?
c2j/c2j@c2j 分別表示用戶名,密碼和服務(wù)名?
?
file:輸出文件的位置和文件名?
?
tables:輸出的表名列表,多個(gè)表中間用逗號(hào)隔開?
?
?
?
2--數(shù)據(jù)庫導(dǎo)入(imp)?
?
首先進(jìn)入命令行?
?
?
?
數(shù)據(jù)庫導(dǎo)入(imp)?
?
在命令行中輸入如下命令:?
?
?
imp ? c2j/c2j@c2j ??
file=c:/table.dmp ??
fromuser=c2j ? ignore=y ??
commit=y ? grants=y
?
?
然后按回車鍵?
?
說明: c2j/c2j@c2j 分別表示用戶名,密碼和服務(wù)名?
?
file:要導(dǎo)入的文件的全路逕?
?
fromuser:指明來源用戶方?
?
ignore:是否忽略對(duì)象創(chuàng)建錯(cuò)誤?
?
commit:上載數(shù)據(jù)緩沖區(qū)中的記錄,上載后是否執(zhí)行提交?
?
?
?
出現(xiàn) 正常終了表示導(dǎo)入成功?
?
打開數(shù)據(jù)庫,看是否導(dǎo)入成功?
?
注:Oralce數(shù)據(jù)庫導(dǎo)入導(dǎo)出時(shí)要確保Oralce服務(wù)啟動(dòng)?
?
以下參考自:http://www.matrix.org.cn/thread.shtml?forumId=36&topicId=23332?
?
一. 導(dǎo)出工具 exp?
?
1. 它是操作系統(tǒng)下一個(gè)可執(zhí)行的文件 存放目錄/ORACLE_HOME/bin?
?
exp導(dǎo)出工具將數(shù)據(jù)庫中數(shù)據(jù)備份壓縮成一個(gè)二進(jìn)制系統(tǒng)文件.可以在不同OS間遷移?
?
它有三種模式:?
?
a. 用戶模式: 導(dǎo)出用戶所有對(duì)象以及對(duì)象中的數(shù)據(jù);?
?
b. 表模式: 導(dǎo)出用戶所有表或者指定的表;?
?
c. 整個(gè)數(shù)據(jù)庫: 導(dǎo)出數(shù)據(jù)庫中所有對(duì)象。?
?
2. 導(dǎo)出工具exp交互式命令行方式的使用的例子?
?
?
$exp test/test123@appdb
Enter array fetch buffer size: 4096 > 回車
Export file: expdat.dmp > m.dmp ?生成導(dǎo)出的文件名?
(1)E(ntire database), (2)U(sers), or (3)T(ables): (2)U > 3
Export table data (yes/no): yes > 回車
Compress extents (yes/no): yes > 回車
Export done in ZHS16GBK character set and ZHS16GBK NCHAR character set
About to export specified tables via Conventional Path ...
Table(T) or Partition(T:P) to be exported: (RETURN to quit) > cmamenu?
要導(dǎo)出的表名
. . exporting table ? ? ? ? ? ? ? ? ? ? ? ?CMAMENU ? ? ? 4336 rows exported
Table(T) or Partition(T:P) to be exported: (RETURN to quit) >要導(dǎo)出的表名n
Table(T) or Partition(T:P) to be exported: (RETURN to quit) > 回車
Export terminated successfully without warnings.
?
?
3. 導(dǎo)出工具exp非交互式命令行方式的例子?
?
?
$exp scott/tiger tables=(emp,dept) file=/directory/scott.dmp grants=y?
說明:把scott用戶里兩個(gè)表emp,dept導(dǎo)出到文件/directory/scott.dmp
$exp scott/tiger tables=emp query=/"where job=/'salesman/' and sal/<1600/" file=/directory/scott2.dmp
?
?
說明:在exp里面加上導(dǎo)出emp的查詢條件job='salesman' and sal<1600?
?
(但我個(gè)人很少這樣用,還是把滿足條件的記錄生成臨時(shí)表后,再exp會(huì)方便一些)?
?
?
$exp parfile=username.par file=/directory1/username_1.dmp,
/directory1/username_2.dmp filesize=2000M log=/directory2/username_exp.log
?
?
參數(shù)文件username.par內(nèi)容?
?
userid=username/userpassword?
?
buffer=8192000?
?
compress=n?
?
grants=y?
?
說明:username.par為導(dǎo)出工具exp用的參數(shù)文件,里面具體參數(shù)可以根據(jù)需要去修改?
?
filesize指定生成的二進(jìn)制備份文件的最大字節(jié)數(shù)?
?
(可用來解決某些OS下2G物理文件的限制及加快壓縮速度和方便刻歷史數(shù)據(jù)光盤等)?
?
二.導(dǎo)入工具 imp?
?
1. 它是操作系統(tǒng)下一個(gè)可執(zhí)行的文件 存放目錄/ORACLE_HOME/bin?
?
imp導(dǎo)入工具將EXP形成的二進(jìn)制系統(tǒng)文件導(dǎo)入到數(shù)據(jù)庫中.?
?
它有三種模式:?
?
a. 用戶模式: 導(dǎo)出用戶所有對(duì)象以及對(duì)象中的數(shù)據(jù);?
?
b. 表模式: 導(dǎo)出用戶所有表或者指定的表;?
?
c. 整個(gè)數(shù)據(jù)庫: 導(dǎo)出數(shù)據(jù)庫中所有對(duì)象。?
?
只有擁有IMP_FULL_DATABASE和DBA權(quán)限的用戶才能做整個(gè)數(shù)據(jù)庫導(dǎo)入?
?
imp步驟:?
?
(1) create table (2) insert data (3) create index (4) create triggers,constraints?
?
2.導(dǎo)入工具imp交互式命令行方式的例子?
?
?
$ imp
Import: Release 8.1.6.0.0 - Production on 星期五 12月 7 17:01:08 2001
(c) Copyright 1999 Oracle Corporation. ?All rights reserved.
用戶名: ?test
口令:****
連接到: Oracle8i Enterprise Edition Release 8.1.6.0.0 - 64bit Production
With the Partitioning option
JServer Release 8.1.6.0.0 - Production
?
?
導(dǎo)入文件: expdat.dmp> /tmp/m.dmp?
?
輸入插入緩沖區(qū)大小(最小為 8192 ) 30720>?
?
經(jīng)由常規(guī)路徑導(dǎo)出由EXPORT:V08.01.06創(chuàng)建的文件?
?
警告: 此對(duì)象由 TEST 導(dǎo)出, 而不是當(dāng)前用戶?
?
已經(jīng)完成ZHS16GBK字符集和ZHS16GBK NCHAR 字符集中的導(dǎo)入?
?
只列出導(dǎo)入文件的內(nèi)容(yes/no):no>?
?
由于對(duì)象已存在, 忽略創(chuàng)建錯(cuò)誤(yes/no):no> yes?
?
導(dǎo)入權(quán)限(yes/no):yes>?
?
導(dǎo)入表數(shù)據(jù)(yes/no):yes>?
?
導(dǎo)入整個(gè)導(dǎo)出文件(yes/no):no> yes?
?
. 正在將TEST的對(duì)象導(dǎo)入到 SCOTT?
?
. . 正在導(dǎo)入表 "CMAMENU" 4336行被導(dǎo)入?
?
成功終止導(dǎo)入,但出現(xiàn)警告。?
?
3.導(dǎo)入工具imp非交互式命令行方式的例子?
?
?
$ imp system/manager fromuser=jones tables=(accts)?
$ imp system/manager fromuser=scott tables=(emp,dept)?
$ imp system/manager fromuser=scott touser=joe tables=emp?
$ imp scott/tiger file = expdat.dmp full=y?
$ imp scott/tiger file = /mnt1/t1.dmp show=n buffer=2048000 ignore=n
?commit=y grants=y full=y log=/oracle_backup/log/imp_scott.log
$ imp system/manager parfile=params.dat?
params.dat 內(nèi)容?
file=dba.dmp show=n ignore=n grants=y fromuser=scott tables=(dept,emp)
?
?
4.導(dǎo)入工具imp可能出現(xiàn)的問題?
?
(1) 數(shù)據(jù)庫對(duì)象已經(jīng)存在?
?
一般情況, 導(dǎo)入數(shù)據(jù)前應(yīng)該徹底刪除目標(biāo)數(shù)據(jù)下的表, 序列, 函數(shù)/過程,觸發(fā)器等;?
?
數(shù)據(jù)庫對(duì)象已經(jīng)存在, 按缺省的imp參數(shù), 則會(huì)導(dǎo)入失敗?
?
如果用了參數(shù)ignore=y, 會(huì)把exp文件內(nèi)的數(shù)據(jù)內(nèi)容導(dǎo)入?
?
如果表有唯一關(guān)鍵字的約束條件, 不合條件將不被導(dǎo)入?
?
如果表沒有唯一關(guān)鍵字的約束條件, 將引起記錄重復(fù)?
?
(2) 數(shù)據(jù)庫對(duì)象有主外鍵約束?
?
不符合主外鍵約束時(shí), 數(shù)據(jù)會(huì)導(dǎo)入失敗?
?
解決辦法: 先導(dǎo)入主表, 再導(dǎo)入依存表?
?
disable目標(biāo)導(dǎo)入對(duì)象的主外鍵約束, 導(dǎo)入數(shù)據(jù)后, 再enable它們?
?
(3) 權(quán)限不夠?
?
如果要把A用戶的數(shù)據(jù)導(dǎo)入B用戶下, A用戶需要有imp_full_database權(quán)限?
?
(4) 導(dǎo)入大表( 大于80M ) 時(shí), 存儲(chǔ)分配失敗?
?
默認(rèn)的EXP時(shí), compress = Y, 也就是把所有的數(shù)據(jù)壓縮在一個(gè)數(shù)據(jù)塊上.?
?
導(dǎo)入時(shí), 如果不存在連續(xù)一個(gè)大數(shù)據(jù)塊, 則會(huì)導(dǎo)入失敗.?
?
導(dǎo)出80M以上的大表時(shí), 記得compress= N, 則不會(huì)引起這種錯(cuò)誤.?
?
(5) imp和exp使用的字符集不同?
?
如果字符集不同, 導(dǎo)入會(huì)失敗, 可以改變unix環(huán)境變量或者NT注冊(cè)表里NLS_LANG相關(guān)信息.?
?
導(dǎo)入完成后再改回來.?
?
(6) imp和exp版本不能往上兼容?
?
imp可以成功導(dǎo)入低版本exp生成的文件, 不能導(dǎo)入高版本exp生成的文件?
?
根據(jù)情況我們可以用?
?
$ imp username/password@connect_string?
?
說明: connect_string 是在/ORACLE_HOME/network/admin/tnsnames.ora?
?
定義的本地或者遠(yuǎn)端數(shù)據(jù)庫的名稱?
?
注意事項(xiàng):?
?
UNIX: /etc/hosts 要定義本地或者遠(yuǎn)端數(shù)據(jù)庫服務(wù)器的主機(jī)名?
?
win98: windows/hosts 和IP地址的對(duì)應(yīng)關(guān)系?
?
win2000: winnt/system32/drivers/etc/hosts?
?
exp?
?
將數(shù)據(jù)庫內(nèi)的各對(duì)象以二進(jìn)制方式下載成damp文件,方便數(shù)據(jù)遷移。?
?
buffer:下載數(shù)據(jù)緩沖區(qū),以字節(jié)為單位,缺省依賴操作系統(tǒng)?
?
consistent:下載期間所涉及的數(shù)據(jù)保持read only,缺省為n?
?
direct:使用直通方式 ,缺省為n?
?
feedback:顯示處理記錄條數(shù),缺省為0,即不顯示?
?
file:輸出文件,缺省為expdat.dmp?
?
filesize:輸出文件大小,缺省為操作系統(tǒng)最大值?
?
indexes:是否下載索引,缺省為n,這是指索引的定義而非數(shù)據(jù),exp不下載索引數(shù)據(jù)?
?
log:log文件,缺省為無,在標(biāo)準(zhǔn)輸出顯示?
?
owner:指明下載的用戶名?
?
query:選擇記錄的一個(gè)子集?
?
rows:是否下載表記錄?
?
tables:輸出的表名列表?
?
導(dǎo)出整個(gè)實(shí)例?
?
?
exp dbuser/oracle file=oradb.dmp log=oradb.log?
full=y consistent=y direct=y
?
?
user應(yīng)具有dba權(quán)限?
?
導(dǎo)出某個(gè)用戶所有對(duì)象?
?
?
exp dbuser/oracle file=dbuser.dmp log=dbuser.log?
owner=dbuser buffer=4096000 feedback=10000
?
?
導(dǎo)出一張或幾張表?
?
?
exp dbuser/oracle file=dbuser.dmp?
log=dbuser.log tables=table1,table2?
buffer=4096000 feedback=10000
?
?
導(dǎo)出某張表的部分?jǐn)?shù)據(jù)?
?
?
exp dbuser/oracle file=dbuser.dmp log=dbuser.log?
tables=table1 buffer=4096000 feedback=10000 query=/”
where col1=/’…/’ and col2 /<…/”
?
?
不可用于嵌套表?
?
以多個(gè)固定大小文件方式導(dǎo)出某張表?
?
?
exp dbuser/oracle file=1.dmp,2.dmp,3.dmp,
… filesize=1000m tables=emp buffer=4096000 feedback=10000
?
?
這種做法通常用在:表數(shù)據(jù)量較大,單個(gè)dump文件可能會(huì)超出文件系統(tǒng)的限制?
?
直通路徑方式?
?
direct=y,取代buffer選項(xiàng),query選項(xiàng)不可用?
?
有利于提高下載速度?
?
consistent選項(xiàng)?
?
自export啟動(dòng)后,consistent=y凍結(jié)來自其它會(huì)話的對(duì)export操作的數(shù)據(jù)對(duì)象的更新,這樣可以保證dump結(jié)果的一致性。但這個(gè)過程不能太長,以免回滾段和聯(lián)機(jī)日志消耗完?
?
imp?
?
將exp下載的dmp文件上載到數(shù)據(jù)庫內(nèi)。?
?
buffer:上載數(shù)據(jù)緩沖區(qū),以字節(jié)為單位,缺省依賴操作系統(tǒng)?
?
commit:上載數(shù)據(jù)緩沖區(qū)中的記錄上載后是否執(zhí)行提交?
?
feeback:顯示處理記錄條數(shù),缺省為0,即不顯示?
?
file:輸入文件,缺省為expdat.dmp?
?
filesize:輸入文件大小,缺省為操作系統(tǒng)最大值?
?
fromuser:指明來源用戶方?
?
ignore:是否忽略對(duì)象創(chuàng)建錯(cuò)誤,缺省為n,在上載前對(duì)象已被建立往往是一個(gè)正常現(xiàn)象,所以此選項(xiàng)建議設(shè)為y?
?
indexes:是否上載索引,缺省為n,這是指索引的定義而非數(shù)據(jù),如果上載時(shí)索引已建立,此選項(xiàng)即使為n也無效,imp自動(dòng)更新索引數(shù)據(jù)?
?
log:log文件,缺省為無,在標(biāo)準(zhǔn)輸出顯示?
?
rows:是否上載表記錄?
?
tables:輸入的表名列表?
?
touser:指明目的用戶方?
?
導(dǎo)入整個(gè)實(shí)例?
?
?
imp dbuser/oracle file=oradb.dmp log=oradb.log?
full=y buffer=4096000 commit=y ignore=y feedback=10000
?
?
導(dǎo)入某個(gè)用戶所有對(duì)象?
?
?
imp dbuser/oracle file=dbuser.dmp log=dbuser.log?
fromuser=dbuser touser=dbuser2 buffer=2048000 commit=y ignore=y feedback=10000
?
?
導(dǎo)入一張或幾張表?
?
?
imp dbuser2/oracle file=user.dmp log=user.log tables=table1,table2?
fromuser=dbuser touser=dbuser2 buffer=2048000 commit=y ignore=y feedback=10000
?
?
以多個(gè)固定大小文件方式導(dǎo)入某張表?
?
?
imp dbuser/oracle file=/(1.dmp,2.dmp,3.dmp,…/) filesize=1000m tables=emp?
fromuser=dbuser touser=dbuser2 buffer=4096000 commit=y ignore=y feedback=10000
轉(zhuǎn)載于:https://www.cnblogs.com/huozhicheng/archive/2011/06/30/2533139.html
總結(jié)
以上是生活随笔為你收集整理的利用外部命令Oralce数据库导入导出的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 最近熬夜看《镇魂》,白天精神不太好,怎么
- 下一篇: silverlight4.0 写文件不能