导入导出工具exp、imp、expdp、impdp

  • 格式:doc
  • 大小:54.50 KB
  • 文档页数:13

下载文档原格式

  / 13
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

导入导出工具exp、imp、expdp、impdp exp和imp是在数据泵之前的逻辑备份工具。

一:导出工具exp

1.$ORACLE_HOME/bin 操作系统下可执行文件

导出工具将数据库中的数据压缩在一个二进制文件

三中模式:

a.表模式:导出用户所有的表或者指定的表

b.用户模式:导出用户下的所有内容

c.整个数据库:导出数据库中的所有对象

c

查看帮助命令

exp help =y

练习

导出前

1)查询数据库的字符集(方法很多只用一种)

SQL> select userenv('language') from dual;

USERENV('LANGUAGE')

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

AMERICAN_AMERICA.WE8ISO8859P1

2)设置Linux操作系统的NLS_LANG环境变量

export NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1

开始导出

使用exp把scott.emp表导出来导出文件名scott.emp

exp help=y imp help=y 查看帮助

exp scott/oracle TABLES=emp file=scott.emp

然后删除scott.emp表

sqlplus scott/oracle

drop table emp;

最后使用导出的文件恢复原来的emp表

imp scott/oracle TABLES=emp file=scott.emp

检查是否成功

select count(*) from scott.emp;

例如:

表模式

exp scott/oracle tables=emp file=emp.dmp

导出多张表

exp scott/oracle tables=emp,dept file=ed.dmp

使用sys用户导出

exp tables=scott.emp file=emp1.dmp

username:sys as sysdba

password: oracle

或者

exp \'sys/oracle as sysdba\' tables=scott.emp file=emp2.dmp

用户模式

导出用户所有的对象

exp scott/oracle owner=scott file=soctt.dmp

全库导出

exp system/oracle full=y file=full.dmp

指定导出片的大小,限制为1g

exp scott/oracle tables=emp file=emp2.dmp

filesize=1g

参数filesize 指定了二进制备份文件的最大字节数

目的是解决某些操作系统下2g物理文件限制以及可以加快压缩和方便刻录光盘等也可以远程导出到本地

exp system/oracle@orcl tables=scott.emp file=emp168.dmp

导入工具:imp

1 该工具是$ORACLE_HOME/bin下一个可执行文件

2 imp将exp生成的二进制文件导入数据库中

只有exp_full_database 和dba权限的用户才能

做整个数据库的导入

grant exp_full_database to scott;

3 imp操作步骤

先create table -->insert data -->create index -->create trigger ,constriants

例子

练习:先删除scott.emp 表的记录,使用备份文件恢复记录

sqlplus scott/oracle

truncate table emp;

select count(*) from emp;

imp scott/oracle tables=emp file=emp.dmp ignore=y

参数ignore=y 表示直接导入数据

检查结果select cont(*) from emp;

将某用户的表导入到另一个用户下:

交互式

imp tables=emp file=emp.dmp fromuser=scott touser=hr

输入用户名:sys as sysdba

输入密码: oracle

非交互式

imp \'sys/oracle as sysdba\' tables=emp file=emp.dmp fromuser=scott touser=hr 约束报错,可以不需要创建约束,加入参数CONSTRAINTS=N

4 导入可能出现的问题

a 数据对象已经存在

解决方法:使用参数ignore=y 会把exp文件的数据内容直接导入

如果表有唯一关键字约束,不符合条件的不导入

如果表没有唯一关键字约束,将引起重复记录

b 数据库对象有主外键约束

不符合主外键约束,数据导入失败

解决方法:先导入主表,在导入从表

或者先禁用主外键,导入完成后在启用

c 权限不够

给予imp_full_database

exp_full_database

d 字符集问题

如果字符集不同,导入失败

查看oracle server端的字符集

select userenv('language') from dual;

查看dump文件字符集

cat scott.dmp |od -x|head -1|awk '{print $2 $3}'|cut -c 3-6

0345

select nls_charset_name(to_number('0354','xxxx')) from dual;

查看oracle client端字符集

echo $NLS_LANG