今天同事說申請了一個從生產匯出的dump檔案,需要匯入測試庫進行測試。之前做的基本都是本庫匯出,本庫匯入的操作,例如:imp test/***@test tables=tbl_fuel file=H:\dev\data\tbl_fuel.dmp ignore=y這樣的指令操作。今天的情況是從一個庫的使用者匯出dump,然後匯入到另外一個庫的使用者中。
匯出:exp p_x/** FILE=tables.dmp TABLES=e.pre_ldp,e.tbl_flight log=tables.log rows=y
幾種錯誤的匯入:imp test/***@test tables=(tbl_a,tbl_b) file=tables.dmp log=test.log full=y提示:IMP-00024: Only one mode (TABLES, FROMUSER, or FULL) can be specifiedTABLES、FROMUSER和FULL參數只能使用一個。
imp test/***@test file=tables.dmp log=test.log ignore=n
提示:Warning: the objects were exported by P_X, not by you
import done in ZHS16CGB231280 character set and AL16UTF16 NCHAR character set
import server uses ZHS16GBK character set (possible charset conversion)
export client uses ZHS16GBK character set (possible charset conversion)
export server uses UTF8 NCHAR character set (possible ncharset conversion)
IMP-00031: Must specify FULL=Y or provide FROMUSER/TOUSER or TABLES arguments
IMP-00000: Import terminated unsuccessfully
FULL=Y、FROMUSER/TOUSER和TABLES參數必須指定其中之一。
imp test/***@test file=tables.dmp log=test.log ignore=n fromuser=user ouser=test
提示:Warning: the objects were exported by P_X, not by you
import done in ZHS16CGB231280 character set and AL16UTF16 NCHAR character set
import server uses ZHS16GBK character set (possible charset conversion)
export client uses ZHS16GBK character set (possible charset conversion)
export server uses UTF8 NCHAR character set (possible ncharset conversion)
IMP-00034: Warning: FromUser "USER" not found in export file
Import terminated successfully with warnings.
說明From User "USER"不包含在dump檔案中。但通過這種方式可以找到是哪個使用者使用exp匯出的這份dump檔案。
imp test/***@test file=tables.dmp log=test.log ignore=n tables=tbl_a提示:Warning: the objects were exported by P_X, not by you
import done in ZHS16CGB231280 character set and AL16UTF16 NCHAR character set
import server uses ZHS16GBK character set (possible charset conversion)
export client uses ZHS16GBK character set (possible charset conversion)
export server uses UTF8 NCHAR character set (possible ncharset conversion)
. importing P_X's objects into TEST
IMP-00033: Warning: Table "TBL_A" not found in export file
說明TBL_A表並不在匯出的dump中,個人認為,因為這裡未使用FROMUSER這些參數,預設就是dump中包含的資料是從本地test使用者的,因此這會報錯。
imp test/***@test file=tables.dmp log=test.log ignore=n fromuser=e touser=test(未建立表結構)imp test/***@test file=tables.dmp log=test.log ignore=y fromuser=e touser=test(已建立表結構)
這裡表示刪除了表後,ignore=n,dump的來源是e這個schema或使用者,匯入到這個測試test使用者下。
當然,由於test使用者沒有匯出庫的一些角色,因此如下這些許可權操作可能會失敗,但不影響使用這些測試。IMP-00017: following statement failed with ORACLE error 1917:
"GRANT UPDATE ON "TBL_A" TO "B_E""
參數:fromuser具體指定那個使用者下的對象需要匯入,所以如果這裡使用p_x,會報錯,因為表不在p_x使用者下。
touser具體指定匯入那個使用者,該參數必須跟fromuser一起使用。
show在螢幕顯示檔案內容,具體不會做匯入操作。
ignore忽略匯入處理程序中建立對象的錯誤(確保資料能夠匯入),但不會忽略寫入資料的錯誤(如匯入的資料跟當前表裡的資料有違反唯一性限制式的錯誤)。
commit該參數為Y時,匯入的過程會提交資料行,若buffer設定得太小,則會過去頻繁的提交資料,對效能有一定的影響。使用commit還有一個好處,就是做測試資料匯入時,如果有些錯誤未插入資料庫,使用commit後會將符合的記錄commit提交,不會導致整個匯入操作復原,因為畢竟是做測試,多一些少一些資料問題不是很大。
full匯入整個檔案。tables匯入表名列表,多個表名,逗號分隔。
rows該參數為Y的時候將匯入資料,預設是匯入資料。但出於某種原因可以將該參數設定成N即不匯入資料行。