今天同事说申请了一个从生产导出的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 specified
TABLES、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
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.
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
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""
"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即不导入数据行。