Oracle exp imp備份 匯出 匯入備份

2021-04-23 09:06:28 字數 4720 閱讀 6731

exp hely=y 說明:

userid 使用者名稱/口令

full 匯出整個檔案 (n)

buffer 資料緩衝區的大小

owner 所有者使用者名稱列表

file 輸出檔案 (expdat.dmp)

tables 表名列表

compress 匯入乙個範圍 (y)

recordlength io 記錄的長度

grants 匯出許可權 (y)

inctype 增量匯出型別

indexes 匯出索引 (y)

record 跟蹤增量匯出 (y)

rows 匯出資料行 (y)

parfile 引數檔名

constraints 匯出限制 (y)

consistent 交叉表一致性

log 螢幕輸出的日誌檔案

statistics 分析物件 (estimate)

direct 直接路徑 (n)

triggers 匯出觸發器 (y)

feedback 顯示每 x 行 (0) 的進度

filesize 各轉儲檔案的最大尺寸

query 選定匯出表子集的子句

下列關鍵字僅用於可傳輸的表空間

transport_tablespace 匯出可傳輸的表空間元資料 (n)

tablespaces 將傳輸的表空間列表

imp hely=y 說明:

userid 使用者名稱/口令

full 匯入整個檔案 (n)

buffer 資料緩衝區大小

fromuser 所有人使用者名稱列表

file 輸入檔案 (expdat.dmp)

touser 使用者名稱列表

show 只列出檔案內容 (n)

tables 表名列表

ignore 忽略建立錯誤 (n)

recordlength io 記錄的長度

grants 匯入許可權 (y)

inctype 增量匯入型別

indexes 匯入索引 (y)

commit 提交陣列插入 (n)

rows 匯入資料行 (y)

parfile 引數檔名

log 螢幕輸出的日誌檔案

constraints 匯入限制 (y)

destroy 覆蓋表空間資料檔案 (n)

indexfile 將表/索引資訊寫入指定的檔案

skip_unusable_indexes 跳過不可用索引的維護 (n)

analyze 執行轉儲檔案中的 analyze 語句 (y)

feedback 顯示每 x 行 (0) 的進度

toid_novalidate 跳過指定型別 id 的校驗

filesize 各轉儲檔案的最大尺寸

recalculate_statistics 重新計算統計值 (n)

下列關鍵字僅用於可傳輸的表空間

transport_tablespace 匯入可傳輸的表空間元資料 (n)

tablespaces 將要傳輸到資料庫的表空間

datafiles 將要傳輸到資料庫的資料檔案

tts_owners 擁有可傳輸表空間集中資料的使用者

匯入注意事項:

(1) 資料庫物件已經存在

一般情況, 匯入資料前應該徹底刪除目標資料下的表, 序列, 函式/過程,觸發器等; 

資料庫物件已經存在, 按預設的imp引數, 則會匯入失敗

如果用了引數ignore=y, 會把exp檔案內的資料內容匯入

如果表有唯一關鍵字的約束條件, 不合條件將不被匯入

如果表沒有唯一關鍵字的約束條件, 將引起記錄重複

(2) 資料庫物件有主外來鍵約束

不符合主外來鍵約束時, 資料會匯入失敗

解決辦法: 先導入主表, 再匯入依存表

disable目標匯入物件的主外來鍵約束, 匯入資料後, 再enable它們

(3)  許可權不夠

如果要把a使用者的資料匯入b使用者下, a使用者需要有imp_full_database許可權 

(4)  匯入大表( 大於80m ) 時, 儲存分配失敗

預設的exp時, compress = y, 也就是把所有的資料壓縮在乙個資料塊上.

匯入時, 如果不存在連續乙個大資料塊, 則會匯入失敗.

匯出80m以上的大表時, 記得compress= n, 則不會引起這種錯誤.

(5) imp和exp使用的字符集不同

如果字符集不同, 匯入會失敗, 可以改變unix環境變數或者nt登錄檔裡nls_lang相關資訊.

匯入完成後再改回來. 

(6) imp和exp版本不能往上相容

imp可以成功匯入低版本exp生成的檔案, 不能匯入高版本exp生成的檔案

使用方法:

例題格式及說明:

1.普通資料庫全部匯出和匯入

exp 使用者/密碼@dbname file=路徑.dmp full=y  --還有其他的引數,看需要進行填寫

$ exp user/pwd file=/dir/***.dmp log=***.log full=y commit=y ignore=y  --全部匯出

$ imp user/pwd file=/dir/***.dmp log=***.log fromuser=dbuser touser=dbuser2 --全部匯入

2.指定使用者全部匯出

/home/oracle/product/9.2.0.4/bin/exp userid=使用者/密碼    --說明:本地的資料庫登入(可以指定其他資料庫,則需新增@dbname)

owner=匯出的使用者名稱 file=匯出路徑存放目錄.dmp log=匯出的日誌資訊.log  --主要:這是不能使用full=y或則會出錯(預設該使用者全匯出)

3.檔案引數匯出

$ exp parfile=username.par // 在引數檔案中輸入所需的引數

引數檔案username.par 內容

userid=username/userpassword

buffer=8192000

compress=n

grants=y

file=/oracle/test.dmp

full=y

4.制定表匯出(分割槽表匯出及條件表匯出)

$ exp user/pwd file=/dir/***.dmp log=***.log tables=table1,table2 --或tables(table1,table2,.....)

$ exp user/pwd file=/dir/***.dmp log=***.log tables=(t1: table1,t2: table2,.....) --t1是分割槽表

$ exp scott/tiger tables=emp query=/"where job=/'salesman/' and sal/<1600/" file=/directory/scott2.dmp 或根據引數檔案進行匯出

5.匯入(一張或多張表)

$ imp user/pwd file=/dir/***.dmp log=***.log tables=(table1,table2) fromuser=dbuser

touser=dbuser2 commit=y ignore=y

$ imp user/pwd file=/dir/***.dmp log=***.log fromuser=dbuser touser=dbuser2

commit=y ignore=y

6.只匯出資料物件不匯出資料

$ exp user/pwd file=/dir/***.dmp log=***.log owner=user rows=n --rows=n/y說明是否匯出資料行

7.分割多個檔案匯出和匯入

$ exp user/pwd file=1.dmp,2.dmp,3.dmp,… filesize=1000m log=***.log full=y

$ imp user/pwd file=1.dmp,2.dmp,3.dmp,… filesize=1000m tables=*** fromuser=dbuser

touser=dbuser2 commit=y ignore=y

8.增量匯出和匯入

a.完全增量匯出(inctype=complete) // 備份整個資料庫

$ exp user/pwd file=/dir/***.dmp log=***.log inctype=complete

b.增量型增量匯出 匯出上一次備份後改變的資料(inctype=incremental)。

$ exp user/pwd file=/dir/***.dmp log=***.log inctype=incremental

c.累計型增量匯出(cumulative) 只匯出自上次"完全"匯出之後資料庫中變化的資訊。

$ exp user/pwd file=/dir/***.dmp log=***.log inctype=cumulative

d.增量匯入:

$ imp usr/pwd full=y inctype=system/restore/inctype --(system: 匯入系統物件,restore: 匯入所有使用者物件)

9.使用sysdba進行匯出和匯入

1. 命令列方式:  

a: windows平台:      

c:/> exp 'sys/sys@instance

as sysdba    --輸入連線字串.

3.如果是寫在引數檔案中,則連線字串需要用雙引號了:userid="sys/change_on_install@instance

oracle exp imp 資料備份

1 oracle11g預設對空表不分配segment,故使用exp匯出oracle11g資料庫時,空表不會匯出。解決辦法 設定deferred segment creation 引數為false後,無論是空表還是非空表,都分配segment。在sqlplus中,執行如下命令 sql alter sy...

oracle exp imp增量備份恢復

增量匯出是一種常用的資料備份方法,它只能對整個資料庫來實施,並且必須作為system來匯出。在進行此種匯出時,系統不要求回答任何問題。匯出檔名預設為export.dmp,如果不希望自己的輸出檔案定名為export.dmp,必須在命令列中指出要用的檔名。增量匯出包括三個型別 1 完全 增量匯出 com...

Oracle EXP IMP引數詳解

exp imp是oracle自帶的匯入匯出命令,運用它,即使不需要那結ui工具也能輕易的完成資料匯出匯入工作,下面是它們的引數 exp引數詳解 使用的格式是 exp keyword value 或 keyword value1,value2,valuen 其中userid是必須的且為第乙個引數 關鍵...