exp与imp使用方法

本文详细介绍了Oracle数据库中EXP与IMP命令的使用方法及参数设置,包括完全导出、用户模式导出、表模式导出及相应的导入方式,并提供了常见问题及其解决办法。

一、EXP:

  有三种主要的方式(完全、用户、表)

  1、完全:

  EXP system/manager BUFFER=64000 FILE=/bak/full.dmp FULL=Y

  如果要执行完全导出,必须具有特殊的权限

  2、用户模式:

  EXP scott/tiger BUFFER=64000 FILE=/bak/scott.dmp OWNER=scott

  这样用户scott的所有对象被输出到文件中。

  3、表模式:

  EXP scott/tiger BUFFER=64000 FILE=/bak/scott.dmp OWNER=scott TABLES=emp

  这样用户SONIC的表emp就被导出,多表的话,用逗号隔开

二、IMP:

  具有三种模式(完全、用户、表)

  1、完全:

  IMP system/manager BUFFER=64000 FILE=/bak/full.dmp FULL=Y

  2、用户模式:

  IMP scott/tiger BUFFER=64000 FILE=/bak/scott.dmp FROMUSER=scott TOUSER=scott

  这样用户scott的所有对象被导入到文件中。必须指定FROMUSER、TOUSER参数,这样才能导入数据。

  3、表模式:

  IMP scott/tiger BUFFER=64000 FILE=/bak/scott.dmp OWNER=scott TABLES=emp

  这样用户scott的表emp就被导入。

三、查看EXP、IMP的帮助信息以及缺省参数信息
[oracle@rac1 ~]$ exp help=y
Export: Release 10.2.0.4.0 - Production on Wed Mar 26 14:14:50 2014

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

You can let Export prompt you for parameters by entering the EXP
command followed by your username/password:

     Example: EXP SCOTT/TIGER

Or, you can control how Export runs by entering the EXP command followed
by various arguments. To specify parameters, you use keywords:

     Format:  EXP KEYWORD=value or KEYWORD=(value1,value2,...,valueN)
     Example: EXP SCOTT/TIGER GRANTS=Y TABLES=(EMP,DEPT,MGR)
               or TABLES=(T1:P1,T1:P2), if T1 is partitioned table

USERID must be the first parameter on the command line.

Keyword    Description (Default)      Keyword      Description (Default)
--------------------------------------------------------------------------
USERID     username/password          FULL         export entire file (N)
BUFFER     size of data buffer        OWNER        list of owner usernames
FILE       output files (EXPDAT.DMP)  TABLES       list of table names
COMPRESS   import into one extent (Y) RECORDLENGTH length of IO record
GRANTS     export grants (Y)          INCTYPE      incremental export type
INDEXES    export indexes (Y)         RECORD       track incr. export (Y)
DIRECT     direct path (N)            TRIGGERS     export triggers (Y)
LOG        log file of screen output  STATISTICS   analyze objects (ESTIMATE)
ROWS       export data rows (Y)       PARFILE      parameter filename
CONSISTENT cross-table consistency(N) CONSTRAINTS  export constraints (Y)

OBJECT_CONSISTENT    transaction set to read only during object export (N)
FEEDBACK             display progress every x rows (0)
FILESIZE             maximum size of each dump file
FLASHBACK_SCN        SCN used to set session snapshot back to
FLASHBACK_TIME       time used to get the SCN closest to the specified time
QUERY                select clause used to export a subset of a table
RESUMABLE            suspend when a space related error is encountered(N)
RESUMABLE_NAME       text string used to identify resumable statement
RESUMABLE_TIMEOUT    wait time for RESUMABLE 
TTS_FULL_CHECK       perform full or partial dependency check for TTS
VOLSIZE              number of bytes to write to each tape volume
TABLESPACES          list of tablespaces to export
TRANSPORT_TABLESPACE export transportable tablespace metadata (N)
TEMPLATE             template name which invokes iAS mode export

Export terminated successfully without warnings.

[oracle@rac1 ~]$ imp help=y
Import: Release 10.2.0.4.0 - Production on Wed Mar 26 14:16:26 2014

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

You can let Import prompt you for parameters by entering the IMP
command followed by your username/password:

    Example: IMP SCOTT/TIGER

Or, you can control how Import runs by entering the IMP command followed
by various arguments. To specify parameters, you use keywords:

     Format:  IMP KEYWORD=value or KEYWORD=(value1,value2,...,valueN)
     Example: IMP SCOTT/TIGER IGNORE=Y TABLES=(EMP,DEPT) FULL=N
               or TABLES=(T1:P1,T1:P2), if T1 is partitioned table

USERID must be the first parameter on the command line.

Keyword  Description (Default)       Keyword      Description (Default)
--------------------------------------------------------------------------
USERID   username/password           FULL         import entire file (N)
BUFFER   size of data buffer         FROMUSER     list of owner usernames
FILE     input files (EXPDAT.DMP)    TOUSER       list of usernames
SHOW     just list file contents (N) TABLES       list of table names
IGNORE   ignore create errors (N)    RECORDLENGTH length of IO record
GRANTS   import grants (Y)           INCTYPE      incremental import type
INDEXES  import indexes (Y)          COMMIT       commit array insert (N)
ROWS     import data rows (Y)        PARFILE      parameter filename
LOG      log file of screen output   CONSTRAINTS  import constraints (Y)
DESTROY                overwrite tablespace data file (N)
INDEXFILE              write table/index info to specified file
SKIP_UNUSABLE_INDEXES  skip maintenance of unusable indexes (N)
FEEDBACK               display progress every x rows(0)
TOID_NOVALIDATE        skip validation of specified type ids 
FILESIZE               maximum size of each dump file
STATISTICS             import precomputed statistics (always)
RESUMABLE              suspend when a space related error is encountered(N)
RESUMABLE_NAME         text string used to identify resumable statement
RESUMABLE_TIMEOUT      wait time for RESUMABLE 
COMPILE                compile procedures, packages, and functions (Y)
STREAMS_CONFIGURATION  import streams general metadata (Y)
STREAMS_INSTANTIATION  import streams instantiation metadata (N)
VOLSIZE                number of bytes in file on each volume of a file on tape

The following keywords only apply to transportable tablespaces
TRANSPORT_TABLESPACE import transportable tablespace metadata (N)
TABLESPACES tablespaces to be transported into database
DATAFILES datafiles to be transported into database
TTS_OWNERS users that own data in the transportable tablespace set
Import terminated successfully without warnings.

关键字   说明 (默认值)  

USERID   用户名/口令            
BUFFER   数据缓冲区大小         
FILE     输出文件 (EXPDAT.DMP)  
COMPRESS  导入到一个区 (Y)      
GRANTS    导出权限 (Y)          
INDEXES   导出索引 (Y)          
DIRECT    直接路径 (N)  --直接导出速度较快        
LOG      屏幕输出的日志文件      
ROWS      导出数据行 (Y)        
CONSISTENT 交叉表的一致性 (N)   
FULL        导出整个文件 (N)
OWNER      所有者用户名列表
TABLES     表名列表
RECORDLENGTH   IO记录的长度
INCTYPE     增量导出类型
RECORD       跟踪增量导出 (Y)
TRIGGERS     导出触发器 (Y)
STATISTICS    分析对象 (ESTIMATE)
PARFILE      参数文件名
CONSTRAINTS  导出的约束条件 (Y)
OBJECT_CONSISTENT    只在对象导出期间设置为只读的事务处理 (N)
FEEDBACK             每 x 行显示进度 (0)
FILESIZE             每个转储文件的最大大小
FLASHBACK_SCN        用于将会话快照设置回以前状态的 SCN
FLASHBACK_TIME       用于获取最接近指定时间的 SCN 的时间
QUERY                用于导出表的子集的 select 子句
RESUMABLE            遇到与空格相关的错误时挂起 (N)
RESUMABLE_NAME       用于标识可恢复语句的文本字符串
RESUMABLE_TIMEOUT    RESUMABLE 的等待时间
TTS_FULL_CHECK       对 TTS 执行完整或部分相关性检查
TABLESPACES          要导出的表空间列表
TRANSPORT_TABLESPACE 导出可传输的表空间元数据 (N)
TEMPLATE             调用 iAS 模式导出的模板名


四、常见问题
1、数据库对象已经存在
一般情况导入数据前应该彻底删除目标数据下的表序列函数/过程,触发器等;  数据库对象已经存在按缺省的imp参数则会导入失败。
如果用了参数
ignore=y, 会把exp文件内的数据内容导入如果表有唯一关键字的约束条件不合条件将不被导入如果表没有唯一关键字的约束条件将引起记录重复

2、
权限不够
要把A用户的数据导入B用户下, A用户需要有imp_full_database权限

3、字符集不同
如果字符集不同导入会失败。修改环境变量NLS_LANG,等导入完成后,再还原即可

4、
impexp版本不能往上兼容
可以从低版本导入高版本,但不能从高版本导入到低版本。

5、
导入大表大于80M ) 存储分配失败
默认的EXP, compress = Y, 也就是把所有的数据压缩在一个数据块上

导入时如果不存在连续一个大数据块则会导入失败。 导出80M以上的大表时记得compress= N, 则不会引起这种错误


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27500440/viewspace-1129908/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/27500440/viewspace-1129908/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值