EXPDP和IMPDP简单测试

一、EXPDP和IMPDP使用说明 

Oracle Database 10g引入了最新的数据泵(Data Dump)技术,数据泵导出导入(EXPDP和IMPDP)的作用 

1)实现逻辑备份和逻辑恢复. 
2)在数据库用户之间移动对象. 
3)在数据库之间移动对象 
4)实现表空间搬移. 

二、数据泵导出导入与传统导出导入的区别 

在10g之前,传统的导出和导入分别使用EXP工具和IMP工具,从10g开始,不仅保留了原有的EXP和IMP工具,还提供了数据泵导出导入工具EXPDP和IMPDP.
使用EXPDP和IMPDP时应该注意的事项: 

1)EXP和IMP是客户端工具程序,它们既可以在可以客户端使用,也可以在服务端使用。 
2)EXPDP和IMPDP是服务端的工具程序,他们只能在ORACLE服务端使用,不能在客户端使用。 

3)IMP只适用于EXP导出文件,不适用于EXPDP导出文件;IMPDP只适用于EXPDP导出文件,而不适用于EXP导出文件。 

数据泵导出包括导出表,导出方案,导出表空间,导出数据库4种方式. 

使用EXPDP工具时,其转储文件只能被存放在DIRECTORY对象对应的OS目录中,而不能直接指定转储文件所在的OS目录.因此,使用EXPDP工具时,必须首先建立
DIRECTORY对象.并且需要为数据库用户授予使用DIRECTORY对象权限.
======================================导出/导入表=====================================
1、以sys身份登录,创建目录和授权用户

C:UsersAdministrator>sqlplus / as sysdba;

SQL*Plus: Release 11.2.0.1.0 Production on 星期五 10月 17 23:16:23 2014

Copyright (c) 1982, 2010, Oracle. All rights reserved.

连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> create directory test_dump as 'd:dumpDirectory';

目录已创建。

SQL> grant read,write on directory test_dump to scott;

授权成功。

2、导出scott.emp表,注意tables=emp后不要加分号,否则出错。

C:UsersAdministrator>expdp scott/tiger directory=test_dump dumpfile=testExpdpScott.emp tables=emp

Export: Release 11.2.0.1.0 - Production on 星期五 10月 17 23:51:29 2014

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
启动 "SCOTT"."SYS_EXPORT_TABLE_01": scott/******** directory=test_dump dumpfile=testExpdpScott.emp tables=emp
正在使用 BLOCKS 方法进行估计...
处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 64 KB
处理对象类型 TABLE_EXPORT/TABLE/TABLE
处理对象类型 TABLE_EXPORT/TABLE/INDEX/INDEX
处理对象类型 TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
处理对象类型 TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
处理对象类型 TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
处理对象类型 TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . 导出了 "SCOTT"."EMP" 8.570 KB 14 行
已成功加载/卸载了主表 "SCOTT"."SYS_EXPORT_TABLE_01"
******************************************************************************
SCOTT.SYS_EXPORT_TABLE_01 的转储文件集为:
D:DUMPDIRECTORYTESTEXPDPSCOTT.EMP
作业 "SCOTT"."SYS_EXPORT_TABLE_01" 已于 23:52:00 成功完成

3、以scott身份登录,删除emp表;再用impdp导入该表

SQL> show user;
USER 为 "SCOTT"
SQL> drop table emp;

表已删除。

SQL> select * from emp;
select * from emp
*1 行出现错误:
ORA-00942: 表或视图不存在
----------------------------------------------------------------------------------------
C:UsersAdministrator>impdp scott/tiger directory=test_dump dumpfile=testExpdpScott.emp

Import: Release 11.2.0.1.0 - Production on 星期五 10月 17 23:55:33 2014

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
已成功加载/卸载了主表 "SCOTT"."SYS_IMPORT_FULL_01"
启动 "SCOTT"."SYS_IMPORT_FULL_01": scott/******** directory=test_dump dumpfile=testExpdpScott.emp
处理对象类型 TABLE_EXPORT/TABLE/TABLE
处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA
. . 导入了 "SCOTT"."EMP" 8.570 KB 14 行
处理对象类型 TABLE_EXPORT/TABLE/INDEX/INDEX
处理对象类型 TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
处理对象类型 TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
处理对象类型 TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
处理对象类型 TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
作业 "SCOTT"."SYS_IMPORT_FULL_01" 已于 23:55:39 成功完成
------------------------------------------------------------------------------------------
SQL> select * from emp;

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- -------------- ---------- ---------- ----------
7369 SMITH CLERK 7902 17-12月-80 800 20
7499 ALLEN SALESMAN 7698 20-2月 -81 1600 300 30
7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30

……表导入成功,已恢复。在导出导入的过程中可加入logfile参数,指定日志文件名称。如:logfile=testimpdp.log

==================================导出/导入方案==========================================

C:UsersAdministrator>expdp scott/tiger directory=test_dump dumpfile=schema.dmp logfile=expdp_schema.log schemas=system

Export: Release 11.2.0.1.0 - Production on 星期六 10月 18 00:01:36 2014

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
启动 "SCOTT"."SYS_EXPORT_SCHEMA_01": scott/******** directory=test_dump dumpfile=schema.dmp logfile=expdp_schema.log schemas=system
正在使用 BLOCKS 方法进行估计...
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 320 KB
处理对象类型 SCHEMA_EXPORT/USER
处理对象类型 SCHEMA_EXPORT/SYSTEM_GRANT
处理对象类型 SCHEMA_EXPORT/ROLE_GRANT
处理对象类型 SCHEMA_EXPORT/DEFAULT_ROLE
处理对象类型 SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
处理对象类型 SCHEMA_EXPORT/SYNONYM/SYNONYM
处理对象类型 SCHEMA_EXPORT/TYPE/TYPE_SPEC
……

导入:C:UsersAdministrator>impdp scott/tiger directory=test_dump dumpfile=schema.dmp logfile=impdp_schema.log schemas=system

============================导出/导入表空间=============================================

C:UsersAdministrator>expdp scott/tiger directory=test_dump dumpfile=ts.dmp logfile=testExpdpTableSpace.log tablespaces=users

Export: Release 11.2.0.1.0 - Production on 星期六 10月 18 00:16:50 2014

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
启动 "SCOTT"."SYS_EXPORT_TABLESPACE_01": scott/******** directory=test_dump dumpfile=ts.dmp logfile=testExpdpTableSpace.log 
tablespaces=users
正在使用 BLOCKS 方法进行估计...
处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 1.125 MB
处理对象类型 TABLE_EXPORT/TABLE/TABLE
处理对象类型 TABLE_EXPORT/TABLE/INDEX/INDEX
处理对象类型 TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
处理对象类型 TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
处理对象类型 TABLE_EXPORT/TABLE/COMMENT
处理对象类型 TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
处理对象类型 TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . 导出了 "OE"."PURCHASEORDER" 243.9 KB 132 行
. . 导出了 "OE"."SUBCATEGORY_REF_LIST_NESTEDTAB" 6.585 KB 21 行
. . 导出了 "OE"."PRODUCT_REF_LIST_NESTEDTAB" 12.50 KB 288 行
. . 导出了 "OE"."CATEGORIES_TAB" 14.15 KB 22 行
. . 导出了 "SCOTT"."DEPT" 5.937 KB 4 行
. . 导出了 "SCOTT"."EMP" 8.570 KB 14 行
. . 导出了 "SCOTT"."EMP2" 8.570 KB 14 行
. . 导出了 "SCOTT"."EMP3" 8.078 KB 2 行
. . 导出了 "SCOTT"."SALGRADE" 5.867 KB 5 行
. . 导出了 "SCOTT"."TEST" 5.085 KB 5 行
. . 导出了 "SCOTT"."BONUS" 0 KB 0 行
. . 导出了 "SH"."DIMENSION_EXCEPTIONS" 0 KB 0 行
已成功加载/卸载了主表 "SCOTT"."SYS_EXPORT_TABLESPACE_01"

******************************************************************************
SCOTT.SYS_EXPORT_TABLESPACE_01 的转储文件集为:
D:DUMPDIRECTORYTS.DMP
作业 "SCOTT"."SYS_EXPORT_TABLESPACE_01" 已于 00:17:49 成功完成

导入: C:UsersAdministrator>impdp scott/tiger directory=test_dump dumpfile=ts.dmp logfile=testImpdpTableSpace.log tablespaces=users

============================导出/导入数据库=============================================

C:UsersAdministrator>expdp scott/tiger directory=test_dump dumpfile=scott_full_expdp.dmp full=y

Export: Release 11.2.0.1.0 - Production on 星期六 10月 18 00:19:48 2014

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
启动 "SCOTT"."SYS_EXPORT_FULL_01": scott/******** directory=test_dump dumpfile=scott_full_expdp.dmp full=y
正在使用 BLOCKS 方法进行估计...
处理对象类型 DATABASE_EXPORT/SCHEMA/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 135.7 MB
处理对象类型 DATABASE_EXPORT/TABLESPACE
处理对象类型 DATABASE_EXPORT/PROFILE
处理对象类型 DATABASE_EXPORT/SYS_USER/USER
处理对象类型 DATABASE_EXPORT/SCHEMA/USER
处理对象类型 DATABASE_EXPORT/ROLE
处理对象类型 DATABASE_EXPORT/GRANT/SYSTEM_GRANT/PROC_SYSTEM_GRANT
处理对象类型 DATABASE_EXPORT/SCHEMA/GRANT/SYSTEM_GRANT
处理对象类型 DATABASE_EXPORT/SCHEMA/ROLE_GRANT
……

导入:C:UsersAdministrator>impdp scott/tiger directory=test_dump dumpfile=scott_full_expdp.dmp full=y

原文地址:https://www.cnblogs.com/rusking/p/4032346.html