Oracle 数据泵 expdp/impdp 总结|Oracle expdp and impdp Usage

概述

ORACLE 10G 开始推出了数据泵(expdp /impdp)进行数据导入导出,可以使用并行参数选项,因此,相对于传统的 #exp 命令来说,执行效率更高。

expdp/impdp 和 exp/imp 的区别

  • exp和imp是客户端工具程序,它们既可以在客户端使用,也可以在服务端使用。
  • expdp和impdp是服务端的工具程序,他们只能在oracle服务端使用,不能在客户端使用。
  • imp只适用于exp导出的文件,不适用于expdp导出文件;impdp只适用于expdp导出的文件,而不适用于exp导出文件。
  • 对于10g以上的服务器,使用exp通常不能导出0行数据的空表,而此时必须使用expdp导出.关键特征

基本用法

创建逻辑目录

该命令不会在操作系统创建真正的目录(请先创建真正的目录),最好以system等管理员创建逻辑目录。

1
2
SQL> conn system/manger@orcl as sysdba
SQL> create directory dump_dir as d:\test\dump;

查看管理员目录

1
SQL> select * from dba_directories;

赋予在指定目录的操作权限

1
SQL> grant read,write on directory dump_dir to scott;

用 expdp 导出数据

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# 导整个数据库
expdp system/manager@orcl directory=dump_dir dumpfile=full.dmp full=y;

# 导出用户
expdp scott/tiger@orcl schemas=scott dumpfile=expdp.dmp directory=dump_dir;

# 导出表
expdp scott/tiger@orcl tables=emp,dept dumpfile=expdp.dmp directory=dump_dir;

# 按查询条件导
expdp scott/tiger@orcl directory=dump_dir dumpfile=expdp.dmp tables=emp query=‘where deptno=20’;

用 impdp 导入数据

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# 导入数据库
CMD> impdp system/manager@orcl directory=dump_dir dumpfile=full.dmp full=y;

# windows 如果找不到 impdp,使用如下命令
cd D:\orcl\product\11\dbhome_1\BIN
impdp.exe system/manager@orcl directory=dump_dir dumpfile=demo.dmp full=y;

# 导入用户(从用户scott导入到用户scott)
CMD> impdp system/manager@orcl directory=dump_dir dumpfile=expdp.dmp schemas=scott;

# 导入表(从scott用户中把表dept和emp导入到system用户中)
CMD> impdp system/manager@orcl directory=dump_dir dumpfile=expdp.dmptables=scott.dept,scott.emp remap_schema=scott:system;

# 追加数据
CMD> impdp system/manager@orcl directory=dump_dir dumpfile=expdp.dmp schemas=systemtable_exists_action

高级用法

自动递增

1
2
# "%U"表示自动生成递增的序列号
expdp scott/tiger directory=dump_dir dumpfile=expdp_%U.dmp

附加日志

1
expdp scott/tiger directory=dump_dir dumpfile=expdp.dmp logfile=expdp.log

采用并行方式备份整库

1
expdp scott/tiger directory=dump_dir dumpfile=expdp.dmp logfile=expdp.log parallel=4

参考|References

http://docs.oracle.com/cd/B19306_01/server.102/b14215/dp_export.htm#i1007829

http://docs.oracle.com/cd/B19306_01/server.102/b14215/dp_import.htm#g1025464

使用 Hugo 构建
主题 StackJimmy 设计