文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>oracle 10g exp/imp导出导入工具的使用...

oracle 10g exp/imp导出导入工具的使用...

时间:2010-08-11  来源:weiqingli190949353

oracle 10g 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指定生成的二进制备份文件的最大字节数
     
     (可用来解决某些os下2g物理文件的限制及加快压缩速度和方便刻历史数据光盘等)
 
二.导入工具 imp
 
1. 它是操作系统下一个可执行的文件 存放目录/oracle_home/bin
 
imp导入工具将exp形成的二进制系统文件导入到数据库中.
 
   它有三种模式:
       a.  用户模式: 导出用户所有对象以及对象中的数据;
       b.  表模式: 导出用户所有表或者指定的表;
       c.  整个数据库: 导出数据库中所有对象。
       
   只有拥有imp_full_database和dba权限的用户才能做整个数据库导入
   
   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) imp和exp使用的字符集不同
      如果字符集不同, 导入会失败, 可以改变unix环境变量或者nt注册表里nls_lang相关信息.
      导入完成后再改回来.
 
(6) imp和exp版本不能往上兼容
imp可以成功导入低版本exp生成的文件, 不能导入高版本exp生成的文件
根据情况我们可以用
$ imp username/password@connect_string
说明: connect_string 是在/oracle_home/network/admin/tnsnames.ora
   定义的本地或者远端数据库的名称
注意事项:
unix: /etc/hosts           要定义本地或者远端数据库服务器的主机名
win98:    windows\hosts             和ip地址的对应关系  
 
win2000:  winnt\system32\drivers\etc\hosts

--------------------------------------------------------------------------------------------------------------------------------------------

下面介绍的是导入导出的实例。
数据导出:
1 将数据库TEST完全导出,用户名system 密码manager 导出到D:\daochu.dmp中
   exp system/manager@TEST file=d:\daochu.dmp full=y
2 将数据库中system用户与sys用户的表导出
   exp system/manager@TEST file=d:\daochu.dmp owner=(system,sys)
3 将数据库中的表inner_notify、notify_staff_relat导出
    exp aichannel/aichannel@TESTDB2 file= d:\data\newsmgnt.dmp tables=(inner_notify,notify_staff_relat)
4 将数据库中的表table1中的字段filed1以&quot;00&quot;打头的数据导出
   exp system/manager@TEST file=d:\daochu.dmp tables=(table1) query=\&quot; where filed1 like '00%'\&quot;
 
  上面是常用的导出,对于压缩,既用winzip把dmp文件可以很好的压缩。
  也可以在上面命令后面 加上 compress=y 来实现。
数据的导入
1 将D:\daochu.dmp 中的数据导入 TEST数据库中。
   imp system/manager@TEST  file=d:\daochu.dmp
   imp aichannel/aichannel@HUST full=y  file=file= d:\data\newsmgnt.dmp ignore=y
   上面可能有点问题,因为有的表已经存在,然后它就报错,对该表就不进行导入。
   在后面加上 ignore=y 就可以了。
2 将d:\daochu.dmp中的表table1 导入
imp system/manager@TEST  file=d:\daochu.dmp  tables=(table1)

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载