Oracle exp/imp导出导入工具的使用

. 出工具 exp

 

1. 它是操作系下一个可行的文件 存放目/ORACLE_HOME/bin

 

   exp出工具将数据中数据压缩成一个二制系文件.可以在不同OS迁移

  

   它有三模式:

       a.  模式: 出用所有象以及象中的数据;

       b.  表模式: 出用所有表或者指定的表;

       c.  整个数据 出数据中所有象。

 

2. 出工具exp交互式命令行方式的使用的例子

 

$exp test/test123@appdb

Enter array fetch buffer size: 4096 >

Export file: expdat.dmp > m.dmp  生成出的文件名

(1)E(ntire database), (2)U(sers), or (3)T(ables): (2)U > 3

Export table data (yes/no): yes >

Compress extents (yes/no): yes >

Export done in ZHS16GBK character set and ZHS16GBK NCHAR character set

About to export specified tables via Conventional Path …

Table(T) or Partition(T:P) to be exported: (RETURN to quit) > cmamenu  出的表名

. . exporting table                        CMAMENU       4336 rows exported

Table(T) or Partition(T:P) to be exported: (RETURN to quit) >出的表名n

Table(T) or Partition(T:P) to be exported: (RETURN to quit) >

Export terminated successfully without warnings.

 

3. 出工具exp非交互式命令行方式的例子

 

$exp scott/tiger tables=(emp,dept) file=/directory/scott.dmp grants=y

 

:scott里两个表emp,dept出到文件/directory/scott.dmp

 

$exp scott/tiger tables=emp query=”where job=’salesman’ and sal<1600″ file=/directory/scott2.dmp

 

:exp里面加上emp查询条件job=’salesman’ and sal<1600

   

    (但我个人很少这样,是把足条件的记录生成临时表后,exp会方便一些)

 

$exp parfile=username.par file=/directory1/username_1.dmp,/directory1/username_2.dmp filesize=2000M log=/directory2/username_exp.log

 

参数文件username.par内容

userid=username/userpassword

buffer=8192000

compress=n

grants=y

 

:username.par为导出工具exp用的参数文件,里面具体参数可以根据需要去修改

 

     filesize指定生成的二份文件的最大字

    

     (可用来解决某些OS2G物理文件的限制及加快压缩速度和方便刻史数据光)

 

.入工具 imp

 

1. 它是操作系下一个可行的文件 存放目/ORACLE_HOME/bin

 

imp入工具将EXP形成的二制系文件入到数据.

 

   它有三模式:

       a.  模式: 出用所有象以及象中的数据;

       b.  表模式: 出用所有表或者指定的表;

       c.  整个数据 出数据中所有象。

      

   只有IMP_FULL_DATABASEDBA限的用才能做整个数据库导

  

   imp步骤

   (1) create table  (2) insert data  (3) create index (4) create triggers,constraints

 

2.入工具imp交互式命令行方式的例子

$ imp

Import: Release 8.1.6.0.0 – Production on 星期五 12 7 17:01:08 2001

(c) Copyright 1999 Oracle Corporation.  All rights reserved.

:  test

口令:****

接到: Oracle8i Enterprise Edition Release 8.1.6.0.0 – 64bit Production

With the Partitioning option

JServer Release 8.1.6.0.0 – Production

入文件: expdat.dmp> /tmp/m.dmp

入插入冲区大小(最小 8192 ) 30720>

由常路径出由EXPORT:V08.01.06建的文件

警告: 象由 TEST , 而不是当前用

完成ZHS16GBK字符集和ZHS16GBK NCHAR 字符集中的

只列出入文件的内容(yes/no)no>

由于象已存在, 忽略错误(yes/no)no> yes

(yes/no)yes>

入表数据(yes/no)yes>

入整个出文件(yes/no)no> yes

. 正在将TEST入到 SCOTT

. . 正在入表                       “CMAMENU”       4336行被

成功入,但出警告。

 

 

3.入工具imp非交互式命令行方式的例子

 

$ imp system/manager fromuser=jones tables=(accts)

$ imp system/manager fromuser=scott tables=(emp,dept)

$ imp system/manager fromuser=scott touser=joe tables=emp

$ imp scott/tiger file = expdat.dmp full=y

$ imp scott/tiger file = /mnt1/t1.dmp show=n buffer=2048000 ignore=n commit=y grants=y full=y log=/oracle_backup/log/imp_scott.log

$ imp system/manager parfile=params.dat

params.dat 内容

file=dba.dmp show=n ignore=n grants=y fromuser=scott tables=(dept,emp)

 

4.入工具imp可能出问题

 

(1) 数据库对象已存在

一般情况, 入数据前应该彻除目数据下的表, 序列, 函数/,器等; 

数据库对象已存在, 按缺省的imp参数, 入失

如果用了参数ignore=y, 会把exp文件内的数据内容

如果表有唯一关键字的束条件, 不合条件将不被

如果表没有唯一关键字的束条件, 将引起记录

 

(2) 数据库对象有主外键约

      不符合主外键约, 数据会入失

      解决: 入主表, 入依存表

disable标导象的主外键约, 入数据后, enable

(3)  限不

如果要把A的数据B, A需要有imp_full_database

 

(4)  入大表( 大于80M ) , 分配失

      EXP, compress = Y,

 

也就是把所有的数据压缩在一个数据.

      , 如果不存在连续一个大数据, 入失.

      80M以上的大表, compress= N, 不会引起这种错误.

 

(5) impexp使用的字符集不同

      如果字符集不同, 入会失, 可以改unix量或者NT注册表里NLS_LANG信息.

      入完成后再改回来.

 

(6) impexp版本不能往上兼容

imp可以成功入低版本exp生成的文件, 不能入高版本exp生成的文件

根据情况我可以用

$ imp username/password@connect_string

: connect_string 是在/ORACLE_HOME/network/admin/tnsnames.ora

   的本地或者端数据的名称

注意事:

UNIX: /etc/hosts           要定本地或者端数据器的主机名

win98:    windowshosts             IP地址的对应关 

 

win2000:  winntsystem32driversetchosts

 

 

 

文章出http://www.diybl.com/course/6_system/linux/Linuxjs/200873/129937_2.html