关于数据泵 的导入导出


10G才开始提供的新工具EXPDP IMPDP
    与EXP和IMP类似 可以算是他们的加强版 但各自独立 互不通用 导出文件只能在服务器端(借助了数据库目录)
    EXP和EMP的功能 数据泵基本都涵盖

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


要使用数据泵必须先创建数据库目录
    数据库目录只允许sys创建
    普通用户使用 必须授权
    
SQL> ! mkdir dp_dir
SQL> create directory dp_dir as '/home/oracle/dp_dir/';

Directory created.

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

Grant succeeded.

SQL>



数据泵导出方法:
    expdp
    导出表emp和dept
    
[oracle@sql dp_dir]$ expdp scott/seker directory=dp_dir dumpfile=exp%U.dmp tables=dept,emp

Export: Release 10.2.0.1.0 - Production on Wednesday, 27 April, 2011 1:39:29

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

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Starting "SCOTT"."SYS_EXPORT_TABLE_01":  scott/******** directory=dp_dir dumpfile=exp%U.dmp tables=dept,emp
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 128 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "SCOTT"."DEPT"                              5.656 KB       4 rows
. . exported "SCOTT"."EMP"                               7.828 KB      14 rows
Master table "SCOTT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:
  /home/oracle/dp_dir/exp01.dmp
Job "SCOTT"."SYS_EXPORT_TABLE_01" successfully completed at 01:39:35

[oracle@sql dp_dir]$ ls
exp01.dmp  expdat.dmp  export.log
[oracle@sql dp_dir]$


scott/seker    连接用户验证
directory=dp_dir 使用的数据库目录
dumpfile=exp%U.dmp 导出文件名 %U 是双位数字序列号 并行导时有意义 默认并行度为1
tables=dept,emp  要导出的表




参数content=设置值
可以导出表结构(metadata_only),表数据(data_only),表结构+表数据(all)
默认值是all

参数tables=设置值
可以指定多个表 用逗号分隔
不写这个参数 就是导出模式下的所有

导出模式下的所有对象 要求对指定模式有足够的权限
schemas=模式名

导出全库 需要使用权限较高的用户sys或system
full=y
expdp '/ as sysdba' directory=dp_dir dumpfile=exp_full_db.dmp full=y

并行度设置 根据CPU的数量设置
PARALLEL=2


导出表空间内的所有数据
tablespaces=表空间名

导出表空间的定义 用于表空间传输
TRANSPORT_TABLESPACES=

NLS_CHARSET_ID
NLS_CHARSET_NAME
alter database character set INTERNAL_USE AL32UTF8;


select * from v$transportable_platform;

SQL> EXECUTE DBMS_TTS.TRANSPORT_SET_CHECK('TBS_SINGLE',true);

PL/SQL 过程已成功完成。

SQL> SELECT * FROM TRANSPORT_SET_VIOLATIONS;

未选定行

说明表空间是自包含的

也可以将参数写在文件中 加载
parfile=参数文件


按where条件导
query=

expdp scott/seker directory=dp_dir dumpfile=exp_emp_deptno_10b.dmp tables=emp query='"where DEPTNO=20"'


排查对象 可以过滤的对象有table,index,trigger,procedure
写在参数文件中不需要转义 写在命令行要转义
include 和 exclude
expdp userid=scott/seker directory=dp_dir dumpfile=exp_emp_deptno_10e.dmp exclude=table:\"\=\'EMP\'\"

[oracle@sql dp_dir]$ cat p.txt
userid=scott/seker
directory=dp_dir
dumpfile=exp_emp_deptno_10d.dmp
exclude=table:"='EMP'"
[oracle@sql dp_dir]$ expdp parfile=p.txt


expdp userid=scott/seker directory=dp_dir dumpfile=exp_emp_deptno_10f.dmp include=table:\"in\(\'EMP\',\'DEPT\'\)\"
[oracle@sql dp_dir]$ cat p.txt
userid=scott/seker
directory=dp_dir
dumpfile=exp_emp_deptno_10g.dmp
include=table:"in('EMP','DEPT')"
[oracle@sql dp_dir]$


数据泵导入方法:
    impdp
    


[oracle@sql dp_dir]$ impdp scott/seker directory=dp_dir dumpfile=exp_schema_scott.dmp tables=emp

Import: Release 10.2.0.1.0 - Production on Wednesday, 27 April, 2011 2:00:55

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

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Master table "SCOTT"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "SCOTT"."SYS_IMPORT_TABLE_01":  scott/******** directory=dp_dir dumpfile=exp_schema_scott.dmp tables=emp
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "SCOTT"."EMP"                               7.828 KB      14 rows
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SCOTT"."SYS_IMPORT_TABLE_01" successfully completed at 02:00:59

[oracle@sql dp_dir]$



scott/seker 连接数据库的验证信息
directory=dp_dir 使用的数据库目录
dumpfile=exp_schema_scott.dmp 导入的文件
tables=emp  导出的表

参数使用方法和导出基本一致

参数content=设置值
可以导出表结构(metadata_only),表数据(data_only),表结构+表数据(all)
默认值是all

参数tables=设置值
可以指定多个表 用逗号分隔
不写这个参数 就是导出模式下的所有

导出模式下的所有对象 要求对指定模式有足够的权限
schemas=模式名

导出全库 需要使用权限较高的用户sys或system
full=y
impdp '/ as sysdba' directory=dp_dir dumpfile=exp_full_db.dmp full=y

并行度设置 根据CPU的数量设置
PARALLEL=2


导出表空间内的所有数据
tablespaces=表空间名

导出表空间的定义 用于表空间传输
TRANSPORT_TABLESPACES=

按where条件导
query=

expdp scott/seker directory=dp_dir dumpfile=exp_emp_deptno_10b.dmp tables=emp query='"where DEPTNO=20"'


排查对象 可以过滤的对象有table,index,trigger,procedure
写在参数文件中不需要转义 写在命令行要转义
include 和 exclude
expdp userid=scott/seker directory=dp_dir dumpfile=exp_emp_deptno_10e.dmp exclude=table:\"\=\'EMP\'\"

[oracle@sql dp_dir]$ cat p.txt
userid=scott/seker
directory=dp_dir
dumpfile=exp_emp_deptno_10d.dmp
exclude=table:"='EMP'"
[oracle@sql dp_dir]$ expdp parfile=p.txt


expdp userid=scott/seker directory=dp_dir dumpfile=exp_emp_deptno_10f.dmp include=table:\"in\(\'EMP\',\'DEPT\'\)\"
[oracle@sql dp_dir]$ cat p.txt
userid=scott/seker
directory=dp_dir
dumpfile=exp_emp_deptno_10g.dmp
include=table:"in('EMP','DEPT')"
[oracle@sql dp_dir]$




REMAP_DATAFILE
该选项用于将源数据文件名转变为目标数据文件名,在不同平台之间搬移表空间时可能需要该选项.
REMAP_DATAFIEL=source_datafie:target_datafile

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

[oracle@sql dp_dir]$ impdp \''/ as sysdba'\' directory=dp_dir dumpfile=exp_full_db.dmp schemas=scott remap_schema=scott:u1

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


利用db_like实现模式复制 不需要导出 直接使用导入命令即可
SQL> create public database link ln_db20 connect to system identified by oracle using 'DB20';

Database link created.

SQL> grant connect,resource to u2 identified by u2;

[oracle@sql dp_dir]$ impdp \''/ as sysdba'\' network_link=ln_db20 schemas=scott remap_schema=scott:u2


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值