数据泵IMPDP 导入工具的使用


数据的导入导出时数据库经常处理的作业之一,Oracle 提供了IMPIMPDP以及SQL*Loader等工具来完成数据的导入工作,其中IMP服务于早期的9i之前的版本,在10g及后续版本,Oracle 提供了数据泵高速导入工具,本文主要介绍IMPDP的使用方法,关于高速导出工具请参照:数据泵EXPDP 导出工具的使用 见 SQL*Loader请参照:SQL*Loader使用方法 见

 

一、数据泵的体系结构

    数据泵的体系结构在数据泵EXPDP 导出工具的使用已列出,再此不再赘述。

 

二、IMPDP支持的接口及导入模式

    导入接口

        使用命令行带参数的

        使用命令行带参数文件

        使用命令行交互

        使用database console(GUI)

    几种常用的导入模式

        导入表

        导入方案

        导入表空间

        导入数据库

        传输表空间模式

               

       

三、演示如何导入

    1.关于查看impdp的帮助,使用以下命令

        [oracle@oradb ~]$ impdp -?  [oracle@oradb ~]$ impdp -help  前者提供帮助信息并开启命令行交互模式

   

    2. 导入表

        --将表dept,emp导入到scott方案中

        impdp scott/tiger directory=dump_scott dumpfile=tab.dmp tables=dept,emp

 

        --将表deptempscott方案导入到system方案中,对于方案的转移,必须使用remap_shcema参数

        impdp system/manage directory=dump_scott dumpfile=tab.dmp tables=scott.dept,scott.emp remap_schema=scott:system

 

    3.导入方案

        --dump_scott目录下的schema.dmp导入到scott方案中

        impdp scott/tiger directory=dump_scott dumpfile=schema.dmp schemas=scott

       

        --scott方案中的所有对象转移到system方案中

        impdp system/RedHat directory=dump_scott dumpfile=schema.dmp schemas=scott remap_schema=scott:system

 

    4.导入表空间

        impdp system/redhat directory=dump_scott dumpfile=tablespace.dmp tablespaces=user01

       

    5.导入数据库

        impdp system/redhat directory=dump_scott dumpfile=full.dmp full=y      

       

    6.将数据对象原样导回(演示从Windows客户端来实现,数据库基于Linux系统)

        Windows客户端来导出scott.emp表,导出后删除该表,再原样导回

        C:/>expdp scott/tiger@list2 directory=dump_scott dumpfile=emp.dmp tables=emp

       

        C:/>sqlplus scott/tiger@list2

 

        SQL*Plus: Release 10.2.0.1.0 - Production on 星期一920 20:50:35 2010

 

        Copyright (c) 1982, 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

 

        SQL> drop table emp;

 

        Table dropped.

 

        SQL> commit;

 

        Commit complete.

        SQL> select count(1) from emp;

        select count(1) from emp

                             *

        ERROR at line 1:

        ORA-00942: table or view does not exist

        SQL> host impdp scott/tiger@list2 directory=dump_scott dumpfile=emp.dmp

 

        SQL> select count(1) from emp;

          COUNT(1)

        ----------

                14     

 

    7.将导出的对象使用remap_schema参数转移到不同的方案

        a.deptscott用户导入到system用户下

            expdp scott/tiger directory=dump_scott dumpfile=dept.dmp tables=dept

               

            方法一:

            impdp system/redhat tables=scott.dept directory=dump_scott dumpfile=dept.dmp remap_schema=scott:system

 

            方法二:

            sql>grant imp_full_database to scott;

            impdp scott/tiger directory=dump_scott dumpfile=dept.dmp tables=dept

                  remap_schema=scott:system table_exists_action=replace

   

        b.scott方案下的所有对象导入到system方案下

            expdp scott/tiger directory=dump_scott dumpfile=allobj.dmp schemas=scott

            impdp scott/tiger directory=dump_scott dumpfile=allobj.dmp remap_schema=scott:system table_exists_action=replace

 

    8.使用remap_datafile参数转移到不同的数据文件(用于不同平台之间存在不同命名方式时)

        下面的示例首先创建了一个参数文件,参数文件名为payroll.par

            directory=pump_scott

            full=y

            dumpfile=datafile.dmp

            remap_datafile='db$:[hrdata.payroll]tbs2.f':'/db/hrdata/payroll/tbs2.f'  --指明重新映射数据文件

   

            impdp scott/tiger PARFILE=payroll.par

   

    9.使用remap_tablespace参数转移到不同的表空间

        impdp scott/scott remap_tablespace=users:tbs1 directory=dpump_scott dumpfile=users.dmp

       

    10.并行导入:

        expdp e/e directory=dump_e dumpfile=a_%u.dmp schemas=e parallel=3

 

        impdp e/e directory=dump_e dumpfile=a_%u.dmp schemas=e parallel=3 table_exists_action=replace

  • 1
  • 2
  • 下一页

相关内容