Oracle的EXP與IMP常用整理

來源:互聯網
上載者:User

關於Oracle資料的匯出與匯入,是在工作中經常用到,尤其是Database Backup。

 exp與imp的用法收集網路,還是那句話,“出來混的,總是要還的” 。

一.定義

  oracle 的exp/imp命令用於實現對資料庫的匯出/匯入操作;
  exp命令用於把資料從遠端資料庫伺服器匯出至本地,產生dmp檔案;
  imp命令用於把本地的資料庫dmp檔案從本地匯入到遠端Oracle資料庫中。

二.文法格式

格式:

匯出

> exp userid/password@instance file='path' log='log.log' 參數

匯入

> imp userid/password@instance file='path' log='log.log' 參數

CMd命令列輸入 imp help=y 或 exp help=y 擷取imp或exp的文法參數資訊:

  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)
  FEEDBACK              每 x 行顯示進度 (0)
  TOID_NOVALIDATE        跳過指定類型 ID 的驗證
  FILESIZE              每個轉儲檔案的最大大小
  STATISTICS            始終匯入預計算的統計資訊
  RESUMABLE              遇到與空格有關的錯誤時掛起 (N)
  RESUMABLE_NAME        用來標識可恢複語句的文本字串
  RESUMABLE_TIMEOUT      RESUMABLE 的等待時間
  COMPILE                編譯過程, 程式包和函數 (Y)

1) 資料匯出:

 1 將資料庫SampleDB完全匯出,使用者名稱system 密碼manager 匯出到E:/SampleDB.dmp中

  exp system/manager@TestDB file=E:/sampleDB.dmp log=E:/sample.log full=y

 2 將資料庫中system使用者與sys使用者的表匯出

  exp system/manager@TestDB file=E:/sampleDB.dmp  log=E:/sample.log owner=(system,sys)

 3 將資料庫中的表 TableA,TableB 匯出

    exp system/manager@TestDB  file=E:/sampleDB.dmp  log=E:/sample.log tables=(TableA,TableB)

 4 將資料庫中的表tableA中的欄位filed1 值為 "王五" 的資料匯出

  exp system/manager@TestDB  file=E:/sampleDB.dmp log=E:/sample.log tables=(tableA)  query=' where filed1='王五'
 
  如果想對dmp檔案進行壓縮,可以在上面命令後面 加上 compress=y 來實現。

  如果想只匯出資料庫物件的結構,參數加rows=no 獲得,全部對象 full=y,忽略各種錯誤 ignore=y

2) 資料的匯入

 1 將備份資料庫檔案中的資料匯入指定的資料庫SampleDB 中,如果 SampleDB 已存在該表,則不再匯入;

  imp system/manager@TEST  file=E:/sampleDB.dmp log=E:/sample.log full=y  ignore=y
 

 2 將d:/daochu.dmp中的表table1 匯入

 imp system/manager@TEST  file=E:/sampleDB.dmp log=E:/sample.log  tables=(table1)

 3. 匯入一個完整資料庫

 imp system/manager file=bible_db log=dible_db full=y ignore=y

 4. 匯入一個或一組指定使用者所屬的全部表、索引和其他對象

 imp system/manager file=E:/sampleDB.dmp log=E:/sample.log fromuser=seapark
 imp system/manager file=E:/sampleDB.dmp log=E:/sample.log fromuser=(seapark,amy,amyc,harold)

 5. 將一個使用者所屬的資料匯入另一個使用者

 imp system/manager file=E:/sampleDB.dmp log=E:/sample.log fromuser=seapark touser=seapark_copy
 imp system/manager file=E:/sampleDB.dmp log=E:/sample.log fromuser=(seapark,amy)
 touser=(seapark1, amy1)

 6. 匯入一個表

 imp system/manager file=E:/sampleDB.dmp log=E:/sample.log fromuser=seapark TABLES=(a,b)

 7. 從多個檔案匯入

 imp system/manager file=(paycheck_1,paycheck_2,paycheck_3,paycheck_4)
 log=paycheck, filesize=1G full=y

 8. 使用參數檔案

 imp system/manager parfile=bible_tables.par
 bible_tables.par參數檔案:
 #Import the sample tables used for the Oracle8i Database Administrator's
 Bible. fromuser=seapark touser=seapark_copy file=seapark log=seapark_import

9. 增量匯入

 imp system./manager inctype= RECTORE FULL=Y  FILE=A

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.