ITPub博客

首页 > 数据库 > Oracle > exp/expdp与imp/impdp的区别

exp/expdp与imp/impdp的区别

Oracle 作者:许愿流星1号 时间:2014-11-20 16:20:12 0 删除 编辑
在平常备库和数据库迁移的时候,当遇到大的数据库的时候在用exp的时候往往是需要好几个小时,耗费大量时间。oracle10g以后可以用expdp来导出数据库花费的时间要远小于exp花费的时间,而且文件也要小很多。

导出命令上的区别:
1.将scott和system用户导出
exp system/manager@prod file=d:\exp.dmp owner=(system.scott)
Expdp system/manager DIRECTORY=hehe DUMPFILE=tab.dmp  SCHEMAS=scott,system
注:如果这样执行expdp,会提示
结果报错:
ORA-39002: 操作无效
ORA-39070: 无法打开日志文件。
ORA-39087: 目录名 hehe 无效

因为对于system来说,它看不到hehe的存在,需要创建,并且授权
create directory dump_dir as 'D:\';
grant read,write on directory hehe to system
SELECT * FROM dba_directories;  可以查看下建立了哪些目录

下边scott用户就不能用hehe目录了,得重新创建其他的,并授权。
2.将scott用户下的emp\dept表导出
exp scott/tiger@prod file=d:\exp_tab.dmp tables=(emp,dept)
Expdp scott/tiger DIRECTORY=hehe DUMPFILE=tab.dmp TABLES=dept,emp logfile=tab.log 如果这里你写成了log=tab.log,是会自动给你换成正确的命令,不用担心

3导出数据库
exp system/manager@prod  full=y file=d:\full.dmp log=d:\full.log
expdp system/manager direcotry=full dumpfile=full.dmp logfile=full.log full=y  ----dumpfile和logfile绝对不能加路径

导入命令上的区别:
1.将scott用户导入另台服务器下的scott用户里
imp system/manager@test file=e:\exp.dmp fromuser=scott touser=scott log=e:\imp.log
impdp system/manager directory=hehe dumpfile=expdp.dmp remap_schema=’scott’:'scott’ logfile=exp.log;
impdp system/manager directory=hehe dumpfile=expdp.dmp remap_schema=’scott’:'scott’,'hr:hr' logfile=exp.log;---导入多用户
2将scott用户下的dept、emp导入到另一台服务器的scott用户下
imp scott/tiger@test file=e:\tab.dmp tables=(emp,dept)
impdp scott/tiger directory=hehe dmpfile=tab.dmp tables=emp,dept

3导入数据库
imp system/manager@test full=y file=e:\dull.dmp log=e:\full.log
impdp system/manager directory=hehe dumpfile=full.dmp full=y logffile=full.log
用数据泵impdp时,要注意这两个参数,尤其是你要导入的库已经存在了这些对象,如果不加这些参数,是会跳过的
.reuse_datafiles默认N  建立表空间时覆盖原有数据文件
REUSE_DATAFIELS={Y | N}

TABLE_EXISTS_ACTION   导入对象已存在时执行的操作。
有效关键字: (SKIP)跳过, APPEND追加, REPLACE替换 和 TRUNCATE截断。
TABBLE_EXISTS_ACTION={SKIP | APPEND | TRUNCATE | FRPLACE }
当设置该选项为SKIP时,导入作业会跳过已存在表处理下一个对象;
当设置为APPEND时,会追加数据,
为TRUNCATE时,导入作业会截断表,然后为其追加新数据;
当设置为REPLACE时,导入作业会删除已存在表,重建表并追加数据,
注意,TRUNCATE选项不适用与簇表和NETWORK_LINK选项
总结expdp和impdp的优势
exp/imp与expdp/impdp区别:
(1) 把用户usera的对象导到用户userb,用法区别在于fromuser=usera touser=userb ,remap_schema=’usera’:'usera’ 。
例如:imp system/passwd fromuser=usera touser=userb file=/oracle/exp.dmp log=/oracle/exp.log;
impdp system/passwd directory=expdp dumpfile=expdp.dmp remap_schema=’usera’:'userb’ logfile=exp.log;
(2) 更换表空间,用exp/imp的时候,要想更改表所在的表空间,需要手工去处理一下,
如alter table xxx move tablespace_new之类的操作。
用impdp只要用remap_tablespace=’tabspace_old’:'tablespace_new’
(3) 当指定一些表的时候,使用exp/imp 时,tables的用法是 tables=(‘table1′,’table2′,’table3′)。
expdp/impdp的用法是tables=’table1′,’table2′,’table3′
(4) 是否要导出数据行
exp (ROWS=Y 导出数据行,ROWS=N 不导出数据行)
expdp content(ALL:对象+导出数据行,DATA_ONLY:只导出对象,METADATA_ONLY:只导出数据的记录)
(5) expdp是[10g]的新特性而且只能在服务器执行。而exp/imp是通用的。
(6) oracle11g中有个新特性,当表无数据时,不分配segment,以节省空间,所以exp导不出空表。解决的办法是用expdp, 当然也可以设置deferred_segment_creation 参数 或者 insert一行,再rollback,但是这样很麻烦。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29893219/viewspace-1340532/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-09-18

  • 博文量
    46
  • 访问量
    430279