Heim  >  Artikel  >  Datenbank  >  数据泵expdp,impdp使用结

数据泵expdp,impdp使用结

WBOY
WBOYOriginal
2016-06-07 16:06:461585Durchsuche

EXPDP,IMPDP远程导出,导入数据库到本地 1.本地建立导出用户hr_exp并完全删除机hr的用户 C:\Users\Administratorsqlplus / as sysdba SQL*Plus: Release 10.2.0.1.0 - Production on 星期一 10月 27 15:11:01 2014 Copyright (c) 1982, 2005, Oracle. All ri

EXPDP,IMPDP远程导出,导入数据库到本地
1.本地建立导出用户hr_exp并完全删除机hr的用户

C:\Users\Administrator>sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on 星期一 10月 27 15:11:01 2014

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


连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> create user hr_exp identified by hr_exp;

用户已创建。

SQL> grant connect,resource,create database link to hr_exp;

授权成功。

SQL> drop user hr cascade;

用户已删除。


2.在操作系统上创建目录


SQL> conn / as sysdba

已连接。

SQL> create or replace directory DIR_EXP as 'd:\direxp';

目录已创建。

SQL> grant read,write on directory DIR_EXP to hr_exp;

授权成功。

3.解锁远程用户的hr的帐户并修改其密码为hr

C:\Users\Administrator>sqlplus system/root@192.168.11.2:1521/orcl

SQL*Plus: Release 10.2.0.1.0 - Production on 星期一 10月 27 15:16:54 2014

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


连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> alter user hr account unlock;

用户已更改。

SQL> alter user hr identified by hr;

用户已更改。

SQL>

4.创建链接


SQL> conn hr_exp/hr_exp
已连接。
SQL> create database link to_exp_hr
2 connect to hr identified by hr
3 using '(DESCRIPTION =
4 (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.11.2)(PORT = 1521))
5 (CONNECT_DATA =
6 (SERVER = DEDICATED)
7 (SID = orcl)
8 )
9 )';

数据库链接已创建。

另外一种数据连接创建方式
SQL> create database link to_exp_hr connect to hr identified by hr using '192.168.11.2:1521/orcl';

SQL> Select 1 from dual@to_exp_hr;

1
----------
1

SQL>

5.导出hr的数据
C:\Users\Administrator>expdp hr_exp/hr_exp@192.168.11.1:1521/orcl directory=DIR_EXP dumpfile=hr_20141027.dmp logfile=hr_20141027.log network_link=to_exp_hr


Export: Release 10.2.0.1.0 - Production on 星期一, 27 10月, 2014 15:21:49

Copyright (c) 2003, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "HR_EXP"."SYS_EXPORT_SCHEMA_01": hr_exp/********@192.168.11.1:1521/orcl di
rectory=DIR_EXP dumpfile=hr_20141027.dmp logfile=hr_20141027.log network_link=to
_exp_hr
正在使用 BLOCKS 方法进行估计...
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 448 KB
处理对象类型 SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
处理对象类型 SCHEMA_EXPORT/SEQUENCE/SEQUENCE
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE
处理对象类型 SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/INDEX
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
处理对象类型 SCHEMA_EXPORT/TABLE/COMMENT
处理对象类型 SCHEMA_EXPORT/PROCEDURE/PROCEDURE
处理对象类型 SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
处理对象类型 SCHEMA_EXPORT/VIEW/VIEW
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/TRIGGER
处理对象类型 SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . 导出了 "HR"."COUNTRIES" 5.992 KB 25 行
. . 导出了 "HR"."DEPARTMENTS" 6.632 KB 27 行
. . 导出了 "HR"."EMPLOYEES" 15.76 KB 107 行
. . 导出了 "HR"."JOBS" 6.609 KB 19 行
. . 导出了 "HR"."JOB_HISTORY" 6.585 KB 10 行
. . 导出了 "HR"."LOCATIONS" 7.710 KB 23 行
. . 导出了 "HR"."REGIONS" 5.289 KB 4 行
已成功加载/卸载了主表 "HR_EXP"."SYS_EXPORT_SCHEMA_01"
******************************************************************************
HR_EXP.SYS_EXPORT_SCHEMA_01 的转储文件集为:
D:\DIREXP\HR_20141027.DMP
作业 "HR_EXP"."SYS_EXPORT_SCHEMA_01" 已于 15:22:20 成功完成


C:\Users\Administrator>

6.授权:expdp,impdp权限授予


SQL> grant imp_full_database,exp_full_database to hr_exp;

授权成功。

SQL>
7.本机导入

C:\Users\Administrator>impdp hr_exp/hr_exp directory=DIR_EXP dumpfile=hr_201410
7.dmp remap_schema=hr:hr_exp exclude=statistics

Import: Release 10.2.0.1.0 - Production on 星期一, 27 10月, 2014 16:54:42

Copyright (c) 2003, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
已成功加载/卸载了主表 "HR_EXP"."SYS_IMPORT_FULL_02"
启动 "HR_EXP"."SYS_IMPORT_FULL_02": hr_exp/******** directory=DIR_EXP dumpfile
hr_20141027.dmp remap_schema=hr:hr_exp exclude=statistics
处理对象类型 SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
处理对象类型 SCHEMA_EXPORT/SEQUENCE/SEQUENCE
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE_DATA
. . 导入了 "HR_EXP"."COUNTRIES" 5.992 KB 25 行
. . 导入了 "HR_EXP"."DEPARTMENTS" 6.632 KB 27 行
. . 导入了 "HR_EXP"."EMPLOYEES" 15.76 KB 107 行
. . 导入了 "HR_EXP"."JOBS" 6.609 KB 19 行
. . 导入了 "HR_EXP"."JOB_HISTORY" 6.585 KB 10 行
. . 导入了 "HR_EXP"."LOCATIONS" 7.710 KB 23 行
. . 导入了 "HR_EXP"."REGIONS" 5.289 KB 4 行
处理对象类型 SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/INDEX
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/COMMENT
处理对象类型 SCHEMA_EXPORT/PROCEDURE/PROCEDURE
处理对象类型 SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
处理对象类型 SCHEMA_EXPORT/VIEW/VIEW
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/TRIGGER
作业 "HR_EXP"."SYS_IMPORT_FULL_02" 已于 16:54:51 成功完成


遇到的问题:未授权

C:\Users\Administrator>impdp hr_exp/hr_exp directory=DIR_EXP dumpfile=hr_20141027.dmp remap_schema=hr:hr_exp exclude=statistics


Import: Release 10.2.0.1.0 - Production on 星期一, 27 10月, 2014 16:51:35

Copyright (c) 2003, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
ORA-31631: 需要权限
ORA-39122: 未授权的用户不能执行 REMAP_SCHEMA 重新映射。


解决方法
C:\Users\Administrator>sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on 星期一 10月 27 16:52:40 2014

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


连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> grant imp_full_database,exp_full_database to hr_exp;

授权成功。

SQL>


其他备注:
hr_exp 本地用户,用来连接远端数据库服务器
DIR_EXP 本地用户下hr_exp的 directory 用户本地指定expdp写入目录,这里是D盘direxp文件夹
to_exp_hr 本地hr_exp用户下的 db link ,用来连接远端数据库服务器

本机EXP数据导出方式:
--这里以SCOTT为例
C:\Users\Administrator>sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on 星期一 10月 27 17:11:23 2014

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


连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> grant connect,resource,create database link to scott;

授权成功。

SQL> grant imp_full_database,exp_full_database to hr_exp;

授权成功。

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

授权成功。

--全部导出(expdp scott/scott@192.168.11.1:1521/orcl directory=DIR_EXP dumpfile=scott_full.dmp logfile=scott_full.log )

C:\Users\Administrator>expdp scott/scott@192.168.11.1:1521/orcl directory=DIR_EXP dumpfile=scott_full.dmp logfile=scott_full.log


Export: Release 10.2.0.1.0 - Production on 星期一, 27 10月, 2014 17:21:29

Copyright (c) 2003, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "SCOTT"."SYS_EXPORT_SCHEMA_01": scott/********@192.168.11.1:1521/orcl dire
ctory=DIR_EXP dumpfile=scott_full.dmp logfile=scott_full.log
正在使用 BLOCKS 方法进行估计...
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 192 KB
处理对象类型 SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/INDEX
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
处理对象类型 SCHEMA_EXPORT/TABLE/COMMENT
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . 导出了 "SCOTT"."DEPT" 5.656 KB 4 行
. . 导出了 "SCOTT"."EMP" 7.820 KB 14 行
. . 导出了 "SCOTT"."SALGRADE" 5.585 KB 5 行
. . 导出了 "SCOTT"."BONUS" 0 KB 0 行
已成功加载/卸载了主表 "SCOTT"."SYS_EXPORT_SCHEMA_01"
******************************************************************************
SCOTT.SYS_EXPORT_SCHEMA_01 的转储文件集为:
D:\DIREXP\SCOTT_FULL.DMP
作业 "SCOTT"."SYS_EXPORT_SCHEMA_01" 已于 17:21:49 成功完成

按表导出
expdp scott/scott@192.168.11.1:1521/orcl directory=DIR_EXP dumpfile=scott_emp.dmp logfile=scott_emp.log tables=scott.emp

C:\Users\Administrator>expdp scott/scott@192.168.11.1:1521/orcl directory=DIR_EXP dumpfile=scott_emp.dmp logfile=scott_emp.log tables=scott.emp


Export: Release 10.2.0.1.0 - Production on 星期一, 27 10月, 2014 17:23:14

Copyright (c) 2003, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "SCOTT"."SYS_EXPORT_TABLE_01": scott/********@192.168.11.1:1521/orcl direc
tory=DIR_EXP dumpfile=scott_emp.dmp logfile=scott_emp.log tables=scott.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" 7.820 KB 14 行
已成功加载/卸载了主表 "SCOTT"."SYS_EXPORT_TABLE_01"
******************************************************************************
SCOTT.SYS_EXPORT_TABLE_01 的转储文件集为:
D:\DIREXP\SCOTT_EMP.DMP
作业 "SCOTT"."SYS_EXPORT_TABLE_01" 已于 17:23:25 成功完成


按表空间导出
Expdp scott/scott@127.0.0.1:1521/orcl DIRECTORY=DIR_EXP DUMPFILE=scott_tablespace.dmp   TABLESPACES=USERS
C:\Users\Administrator> Expdp scott/scott@127.0.0.1:1521/orcl DIRECTORY=DIR_EXP DUMPFILE=scott_tablespace.dmp   TABLESPACES=USERS


Export: Release 10.2.0.1.0 - Production on 星期一, 27 10月, 2014 20:51:25

Copyright (c) 2003, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "SCOTT"."SYS_EXPORT_TABLESPACE_01": scott/********@127.0.0.1:1521/orcl DIR
ECTORY=DIR_EXP DUMPFILE=scott_tablespace.dmp   TABLESPACES=USERS
正在使用 BLOCKS 方法进行估计...
处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 192 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/COMMENT
处理对象类型 TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
处理对象类型 TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . 导出了 "SCOTT"."DEPT" 5.656 KB 4 行
. . 导出了 "SCOTT"."EMP" 7.820 KB 14 行
. . 导出了 "SCOTT"."SALGRADE" 5.585 KB 5 行
. . 导出了 "SCOTT"."BONUS" 0 KB 0 行
已成功加载/卸载了主表 "SCOTT"."SYS_EXPORT_TABLESPACE_01"
******************************************************************************
SCOTT.SYS_EXPORT_TABLESPACE_01 的转储文件集为:
D:\DIREXP\SCOTT_TABLESPACE.DMP
作业 "SCOTT"."SYS_EXPORT_TABLESPACE_01" 已于 20:51:39 成功完成

导出方案(Expdp scott/scott@192.168.11.1:1521/orcl directory=DIR_EXP DUMPFILE=schema.dmp SCHEMAS=scott)


C:\Users\Administrator>Expdp scott/scott@192.168.11.1:1521/orcl directory=DIR_EX
P DUMPFILE=schema.dmp SCHEMAS=scott

Export: Release 10.2.0.1.0 - Production on 星期一, 27 10月, 2014 17:31:23

Copyright (c) 2003, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "SCOTT"."SYS_EXPORT_SCHEMA_01": scott/********@192.168.11.1:1521/orcl dire
ctory=DIR_EXP DUMPFILE=schema.dmp SCHEMAS=scott
正在使用 BLOCKS 方法进行估计...
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 192 KB
处理对象类型 SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/INDEX
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
处理对象类型 SCHEMA_EXPORT/TABLE/COMMENT
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . 导出了 "SCOTT"."DEPT" 5.656 KB 4 行
. . 导出了 "SCOTT"."EMP" 7.820 KB 14 行
. . 导出了 "SCOTT"."SALGRADE" 5.585 KB 5 行
. . 导出了 "SCOTT"."BONUS" 0 KB 0 行
已成功加载/卸载了主表 "SCOTT"."SYS_EXPORT_SCHEMA_01"
******************************************************************************
SCOTT.SYS_EXPORT_SCHEMA_01 的转储文件集为:
D:\DIREXP\SCHEMA.DMP
作业 "SCOTT"."SYS_EXPORT_SCHEMA_01" 已于 17:31:37 成功完成

按查询条件导出(expdp scott/scott@192.168.11.1:1521/orcl tables=scott.emp dumpfile =scott_where.dmp logfile=scott_where.log directory=DIR_EXP query='"where rownum )

C:\Users\Administrator>expdp scott/scott@192.168.11.1:1521/orcl tables=scott.em
p dumpfile =scott_where.dmp logfile=scott_where.log directory=DIR_EXP query='"w
here rownum

Export: Release 10.2.0.1.0 - Production on 星期一, 27 10月, 2014 17:34:28

Copyright (c) 2003, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "SCOTT"."SYS_EXPORT_TABLE_01": scott/********@192.168.11.1:1521/orcl table
s=scott.emp dumpfile =scott_where.dmp logfile=scott_where.log directory=DIR_EXP
query='where rownum 正在使用 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" 7.664 KB 10 行
已成功加载/卸载了主表 "SCOTT"."SYS_EXPORT_TABLE_01"
******************************************************************************
SCOTT.SYS_EXPORT_TABLE_01 的转储文件集为:
D:\DIREXP\SCOTT_WHERE.DMP
作业 "SCOTT"."SYS_EXPORT_TABLE_01" 已于 17:34:39 成功完成


C:\Users\Administrator>


导出的相关命令使用:
1)Ctrl+C组合键:在执行过程中,可以按Ctrl+C组合键退出当前交互模式,退出之后,导出操作不会停止
2)Export> status --查看当前JOB的状态及相关信息
3)Export> stop_job --暂停JOB(暂停job后会退出expor模式)
4)重新进入export模式下:C:\Documents and Settings\Administrator>expdp lttfm/lttfm attach=lttfm.my_job1 --语句后面不带分号
5)Export> start_job --打开暂停的JOB(并未开始重新执行)
6)Export> continue_client --通过此命令重新启动 "LTTFM"."MY_JOB":
7)Export> kill_job --取消当前的JOB并释放相关客户会话(将job删除同时删除dmp文件)
8)Export> exit_client --通过此命令退出export模式(通过4)可再进入export模式下)
注:导出完成后job自动卸


使用exclude,include导出数据
1、Include导出用户中指定类型的指定对象
--仅导出scott用户下以E开头的所有表,包含与表相关的索引,备注等。不包含过程等其它对象类型:
expdp scott/scott@192.168.11.1:1521/orcl dumpfile=scott_e.dmp logfile=scott_e.log directory=DIR_EXP include=TABLE:\"LIKE \'E%\'\"

C:\Users\Administrator>expdp scott/scott@192.168.11.1:1521/orcl dumpfile=scott_e
.dmp logfile=scott_e.log directory=DIR_EXP include=TABLE:\"LIKE \'E%\'\"

Export: Release 10.2.0.1.0 - Production on 星期一, 27 10月, 2014 17:39:55

Copyright (c) 2003, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "SCOTT"."SYS_EXPORT_SCHEMA_01": scott/********@192.168.11.1:1521/orcl dump
file=scott_e.dmp logfile=scott_e.log directory=DIR_EXP include=TABLE:"LIKE \'E%\
'"
正在使用 BLOCKS 方法进行估计...
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 64 KB
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/INDEX
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . 导出了 "SCOTT"."EMP" 7.820 KB 14 行
已成功加载/卸载了主表 "SCOTT"."SYS_EXPORT_SCHEMA_01"
******************************************************************************
SCOTT.SYS_EXPORT_SCHEMA_01 的转储文件集为:
D:\DIREXP\SCOTT_E.DMP
作业 "SCOTT"."SYS_EXPORT_SCHEMA_01" 已于 17:40:09 成功完成

--导出scott用户下排除E$开头的所有表:
expdp scott/scott@192.168.11.1:1521/orcl schemas=scott dumpfile=scott_not_e.dmp logfile=scott_not_e.log directory=DIR_EXP job_name=my_job include=TABLE:\"NOT LIKE \'E$%\'\"

C:\Users\Administrator>expdp scott/scott@192.168.11.1:1521/orcl schemas=scott du
mpfile=scott_not_e.dmp logfile=scott_not_e.log directory=DIR_EXP job_name=my_job
include=TABLE:\"NOT LIKE \'E$%\'\"

Export: Release 10.2.0.1.0 - Production on 星期一, 27 10月, 2014 17:42:42

Copyright (c) 2003, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "SCOTT"."MY_JOB": scott/********@192.168.11.1:1521/orcl schemas=scott dump
file=scott_not_e.dmp logfile=scott_not_e.log directory=DIR_EXP job_name=my_job i
nclude=TABLE:"NOT LIKE \'E$%\'"
正在使用 BLOCKS 方法进行估计...
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 192 KB
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/INDEX
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
处理对象类型 SCHEMA_EXPORT/TABLE/COMMENT
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . 导出了 "SCOTT"."DEPT" 5.656 KB 4 行
. . 导出了 "SCOTT"."EMP" 7.820 KB 14 行
. . 导出了 "SCOTT"."SALGRADE" 5.585 KB 5 行
. . 导出了 "SCOTT"."BONUS" 0 KB 0 行
已成功加载/卸载了主表 "SCOTT"."MY_JOB"
******************************************************************************
SCOTT.MY_JOB 的转储文件集为:
D:\DIREXP\SCOTT_NOT_E.DMP
作业 "SCOTT"."MY_JOB" 已于 17:42:56 成功完成


--仅导出scott用户下的所有存储过程:
expdp scott/scott@192.168.11.1:1521/orcl schemas=scott dumpfile=scott_procedure.dmp logfile=scott_procedure.log directory=DIR_EXP job_name=my_job include=PROCEDUR

2、Exclude导出用户中指定类型的指定对象
--导出lttfm用户下除TABLE类型以外的所有对象,如果表不导出那么与表相关的索引,约束等与表有关联的对象类型也不会被导出:
expdp scott/scott@192.168.11.1:1521/orcl schemas=scott dumpfile=scott_not_table.dmp logfile=scott_not_table.log directory=DIR_EXP job_name=my_job exclude=TABLE;

C:\Users\Administrator>expdp scott/scott@192.168.11.1:1521/orcl schemas=scott du
mpfile=scott_not_table.dmp logfile=scott_not_table.log directory=DIR_EXP job_nam
e=my_job exclude=TABLE

Export: Release 10.2.0.1.0 - Production on 星期一, 27 10月, 2014 17:56:08

Copyright (c) 2003, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "SCOTT"."MY_JOB": scott/********@192.168.11.1:1521/orcl schemas=scott dump
file=scott_not_table.dmp logfile=scott_not_table.log directory=DIR_EXP job_name=
my_job exclude=TABLE
正在使用 BLOCKS 方法进行估计...
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 0 KB
处理对象类型 SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
已成功加载/卸载了主表 "SCOTT"."MY_JOB"
******************************************************************************
SCOTT.MY_JOB 的转储文件集为:
D:\DIREXP\SCOTT_NOT_TABLE.DMP
作业 "SCOTT"."MY_JOB" 已于 17:56:11 成功完成

--导出scott用户下排除E$开头的所有表:
expdp scott/scott@192.168.11.1:1521/orcl dumpfile=scott_not_e_begin.dmp logfile=scott_not_e_begin.log directory=DIR_EXP job_name=my_job exclude=TABLE:\"LIKE\'e$%\'\"
C:\Users\Administrator>expdp scott/scott@192.168.11.1:1521/orcl dumpfile=scott_n
ot_e_begin.dmp logfile=scott_not_e_begin.log directory=DIR_EXP job_name=my_job e
xclude=TABLE:\"LIKE\'e$%\'\"

Export: Release 10.2.0.1.0 - Production on 星期一, 27 10月, 2014 17:58:16

Copyright (c) 2003, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "SCOTT"."MY_JOB": scott/********@192.168.11.1:1521/orcl dumpfile=scott_not
_e_begin.dmp logfile=scott_not_e_begin.log directory=DIR_EXP job_name=my_job exc
lude=TABLE:"LIKE\'e$%\'"
正在使用 BLOCKS 方法进行估计...
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 192 KB
处理对象类型 SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/INDEX
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
处理对象类型 SCHEMA_EXPORT/TABLE/COMMENT
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . 导出了 "SCOTT"."DEPT" 5.656 KB 4 行
. . 导出了 "SCOTT"."EMP" 7.820 KB 14 行
. . 导出了 "SCOTT"."SALGRADE" 5.585 KB 5 行
. . 导出了 "SCOTT"."BONUS" 0 KB 0 行
已成功加载/卸载了主表 "SCOTT"."MY_JOB"
******************************************************************************
SCOTT.MY_JOB 的转储文件集为:
D:\DIREXP\SCOTT_NOT_E_BEGIN.DMP
作业 "SCOTT"."MY_JOB" 已于 17:58:31 成功完成

--导出scott用户下的所有对象,但是对于表类型只导出以e$开头的表:
expdp scott/scott@192.168.11.1:1521/orcl dumpfile=scott_e$_begin.dmp logfile=scott_e$_begin.dmp.log directory=DIR_EXP job_name=my_job exclude=TABLE:\"NOT LIKE \'e$%\'\"

C:\Users\Administrator>expdp scott/scott@192.168.11.1:1521/orcl dumpfile=scott_e
$_begin.dmp logfile=scott_e$_begin.dmp.log directory=DIR_EXP job_name=my_job exc
lude=TABLE:\"NOT LIKE \'e$%\'\"

Export: Release 10.2.0.1.0 - Production on 星期一, 27 10月, 2014 18:00:13

Copyright (c) 2003, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "SCOTT"."MY_JOB": scott/********@192.168.11.1:1521/orcl dumpfile=scott_e$_
begin.dmp logfile=scott_e$_begin.dmp.log directory=DIR_EXP job_name=my_job exclu
de=TABLE:"NOT LIKE \'e$%\'"
正在使用 BLOCKS 方法进行估计...
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 0 KB
处理对象类型 SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
已成功加载/卸载了主表 "SCOTT"."MY_JOB"
******************************************************************************
SCOTT.MY_JOB 的转储文件集为:
D:\DIREXP\SCOTT_E$_BEGIN.DMP
作业 "SCOTT"."MY_JOB" 已于 18:00:25 成功完成

--dba导出所有数据
Expdp system/root DIRECTORY=DIR_EXP DUMPFILE=super.dmp FULL=Y

IMPDP介绍


 数据泵导出导入(EXPDP和IMPDP)的作用
  1、实现逻辑备份和逻辑恢复。
  2、在数据库用户之间移动对象。
  3、在数据库之间移动对象
  4、实现表空间搬移。 数据泵导出导入与传统导出导入的区别:
IMPDP命令行选项与EXPDP有很多相同的,不同的有:
1、REMAP_DATAFILE
该选项用于将源数据文件名转变为目标数据文件名,在不同平台之间搬移表空间时可能需要该选项.
REMAP_DATAFIEL=source_datafie:target_datafile

2、REMAP_SCHEMA
该选项用于将源方案的所有对象装载到目标方案中.
REMAP_SCHEMA=source_schema:target_schema

3、REMAP_TABLESPACE
将源表空间的所有对象导入到目标表空间中
REMAP_TABLESPACE=source_tablespace:targettablespace

如果是多个表空间,则用逗号分开,如REMAP_TABLESPACE=source_tablespace1:targettablespace1,source_tablespace2:targettablespace2

4、REUSE_DATAFILES
该选项指定建立表空间时是否覆盖已存在的数据文件.默认为N
REUSE_DATAFIELS={Y | N}

5、SKIP_UNUSABLE_INDEXES
指定导入是是否跳过不可使用的索引,默认为N

6、SQLFILE
指定将导入要指定的索引DDL操作写入到SQL脚本中
SQLFILE=[directory_object:]file_name
Impdp scott/tiger DIRECTORY=dump DUMPFILE=tab.dmp SQLFILE=a.sql

7、STREAMS_CONFIGURATION
指定是否导入流元数据(Stream Matadata),默认值为Y.

8、TABLE_EXISTS_ACTION
该选项用于指定当表已经存在时导入作业要执行的操作,默认为SKIP
TABBLE_EXISTS_ACTION={SKIP | APPEND | TRUNCATE | FRPLACE }
当设置该选项为SKIP时,导入作业会跳过已存在表处理下一个对象;当设置为APPEND时,会追加数据,为TRUNCATE时,导入作业会截断表,然后为其追加新数据;当设置为REPLACE时,导入作业会删除已存在表,重建表病追加数据,注意,TRUNCATE选项不适用与簇表和NETWORK_LINK选项

9、TRANSFORM
该选项用于指定是否修改建立对象的DDL语句
TRANSFORM=transform_name:value[:object_type]
Transform_name用于指定转换名,其中SEGMENT_ATTRIBUTES用于标识段属性(物理属性,存储属性,表空间,日志等信息),STORAGE用于标识段存储属性,VALUE用于指定是否包含段属性或段存储属性,object_type用于指定对象类型.
Impdp scott/tiger directory=dump dumpfile=tab.dmp Transform=segment_attributes:n:table

10、TRANSPORT_DATAFILES
该选项用于指定搬移空间时要被导入到目标数据库的数据文件
TRANSPORT_DATAFILE=datafile_name
Datafile_name用于指定被复制到目标数据库的数据文件
Impdp system/manager DIRECTORY=dump DUMPFILE=tts.dmp
TRANSPORT_DATAFILES=’/user01/data/tbs1.f’调用IMPDP


table_exists_action=replace:表如果存在,则替换
1、按表导入
HR_20141027.dmp文件中的表,此文件是以hr用户按schemas=hr导出的:
impdp hr_exp/hr_exp@192.168.11.1:1521/orcl dumpfile =HR_20141027.dmp logfile=hr_20141027.log directory=DIR_EXP remap_schema=hr:hr_exp exclude=statistics tables=hr.jobs job_name=my_job table_exists_action=replace

C:\Users\Administrator>impdp hr_exp/hr_exp@192.168.11.1:1521/orcl dumpfile =HR_2
0141027.dmp logfile=hr_20141027.log directory=DIR_EXP remap_schema=hr:hr_exp
exclude=statistics tables=hr.jobs job_name=my_job table_exists_action=replace

Import: Release 10.2.0.1.0 - Production on 星期一, 27 10月, 2014 21:32:01

Copyright (c) 2003, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
已成功加载/卸载了主表 "HR_EXP"."MY_JOB"
启动 "HR_EXP"."MY_JOB": hr_exp/********@192.168.11.1:1521/orcl dumpfile =HR_201
41027.dmp logfile=hr_20141027.log directory=DIR_EXP remap_schema=hr:hr_exp exclu
de=statistics tables=hr.jobs job_name=my_job table_exists_action=replace
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE_DATA
. . 导入了 "HR_EXP"."JOBS" 6.609 KB 19 行
处理对象类型 SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/INDEX
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/COMMENT
作业 "HR_EXP"."MY_JOB" 已于 21:32:06 成功完成


2、按用户导入(可以将用户信息直接导入,即如果用户信息不存在的情况下也可以直接导入)
impdp hr_exp/hr_exp@192.168.11.1:1521/orcl schemas=hr dumpfile =HR_20141027.dmp logfile=hr_20141027.log directory=DIR_EXP job_name=my_job

C:\Users\Administrator>impdp hr_exp/hr_exp@192.168.11.1:1521/orcl schemas=hr du
mpfile =HR_20141027.dmp logfile=hr_20141027.log directory=DIR_EXP job_name=my_jo
b

Import: Release 10.2.0.1.0 - Production on 星期一, 27 10月, 2014 21:33:29

Copyright (c) 2003, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
已成功加载/卸载了主表 "HR_EXP"."MY_JOB"
启动 "HR_EXP"."MY_JOB": hr_exp/********@192.168.11.1:1521/orcl schemas=hr dumpf
ile =HR_20141027.dmp logfile=hr_20141027.log directory=DIR_EXP job_name=my_job
处理对象类型 SCHEMA_EXPORT/USER
处理对象类型 SCHEMA_EXPORT/SYSTEM_GRANT
处理对象类型 SCHEMA_EXPORT/ROLE_GRANT
处理对象类型 SCHEMA_EXPORT/DEFAULT_ROLE
处理对象类型 SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
处理对象类型 SCHEMA_EXPORT/SEQUENCE/SEQUENCE
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE_DATA
. . 导入了 "HR"."COUNTRIES" 5.992 KB 25 行
. . 导入了 "HR"."DEPARTMENTS" 6.632 KB 27 行
. . 导入了 "HR"."EMPLOYEES" 15.76 KB 107 行
. . 导入了 "HR"."JOBS" 6.609 KB 19 行
. . 导入了 "HR"."JOB_HISTORY" 6.585 KB 10 行
. . 导入了 "HR"."LOCATIONS" 7.710 KB 23 行
. . 导入了 "HR"."REGIONS" 5.289 KB 4 行
处理对象类型 SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/INDEX
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
处理对象类型 SCHEMA_EXPORT/TABLE/COMMENT
处理对象类型 SCHEMA_EXPORT/PROCEDURE/PROCEDURE
处理对象类型 SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
处理对象类型 SCHEMA_EXPORT/VIEW/VIEW
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/TRIGGER
处理对象类型 SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
作业 "HR_EXP"."MY_JOB" 已于 21:33:40 成功完成

3、不通过expdp的步骤生成dmp文件而直接导入的方法:
--从源数据库中向目标数据库导入表p_street_area

--远程数据库的操作代码
C:\Documents and Settings\Administrator>expdp hr/hr@192.168.11.2:1521/orcl direc
tory=EXPDP_HOME dumpfile=hr_exp.dmp logfile=hr_exp.log

Export: Release 10.2.0.1.0 - Production on 星期一, 27 10月, 2014 21:46:21

Copyright (c) 2003, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "HR"."SYS_EXPORT_SCHEMA_01": hr/********@192.168.11.2:1521/orcl directory=
EXPDP_HOME dumpfile=hr_exp.dmp logfile=hr_exp.log
正在使用 BLOCKS 方法进行估计...
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 448 KB
处理对象类型 SCHEMA_EXPORT/USER
处理对象类型 SCHEMA_EXPORT/SYSTEM_GRANT
处理对象类型 SCHEMA_EXPORT/ROLE_GRANT
处理对象类型 SCHEMA_EXPORT/DEFAULT_ROLE
处理对象类型 SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
处理对象类型 SCHEMA_EXPORT/SEQUENCE/SEQUENCE
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE
处理对象类型 SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/INDEX
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
处理对象类型 SCHEMA_EXPORT/TABLE/COMMENT
处理对象类型 SCHEMA_EXPORT/PROCEDURE/PROCEDURE
处理对象类型 SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
处理对象类型 SCHEMA_EXPORT/VIEW/VIEW
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/TRIGGER
处理对象类型 SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . 导出了 "HR"."COUNTRIES" 6.085 KB 25 行
. . 导出了 "HR"."DEPARTMENTS" 6.632 KB 27 行
. . 导出了 "HR"."EMPLOYEES" 15.76 KB 107 行
. . 导出了 "HR"."JOBS" 6.609 KB 19 行
. . 导出了 "HR"."JOB_HISTORY" 6.585 KB 10 行
. . 导出了 "HR"."LOCATIONS" 7.710 KB 23 行
. . 导出了 "HR"."REGIONS" 5.289 KB 4 行
已成功加载/卸载了主表 "HR"."SYS_EXPORT_SCHEMA_01"
******************************************************************************
HR.SYS_EXPORT_SCHEMA_01 的转储文件集为:
D:\EXPDP_HOME\HR_EXP.DMP
作业 "HR"."SYS_EXPORT_SCHEMA_01" 已于 21:46:54 成功完成C:\Documents and Settings\Administrator>sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on 星期一 10月 27 21:42:09 2014

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


连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> create or replace directory EXPDP_HOME as 'd:\expdp_home';

目录已创建。


SQL> grant read,write on directory EXPDP_HOME to hr;

授权成功。

--从源数据库中向目标数据库导入表p_street_area
impdp gwm/gwm directory=dir_dp NETWORK_LINK=igisdb tables=p_street_area logfile=p_street_area.log job_name=my_job
igisdb是目的数据库与源数据的链接名,dir_dp是目的数据库上的目录

4、更换表空间
采用remap_tablespace参数
--导出gwm用户下的所有数据
expdp system/orcl directory=data_pump_dir dumpfile=gwm.dmp SCHEMAS=gwm
注:如果是用sys用户导出的用户数据,包括用户创建、授权部分,用自身用户导出则不含这些内容
--以下是将gwm用户下的数据全部导入到表空间gcomm(原来为gmapdata表空间下)下
impdp system/orcl directory=data_pump_dir dumpfile=gwm.dmp remap_tablespace=gmapdata:gcomm

查看目录权限
SQL> SELECT privilege, directory_name, DIRECTORY_PATH FROM user_tab_privs t, all_directories d WHERE t.table_name(+) = d.directory_name ORDER BY 2, 1;

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn