首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Oracle导入导出

如果爱一个人,那就爱整个的他,实事求是地照他本来的面目去爱他,而不是脱离实际希望他这样那样的。-------------托尔斯泰

用开心的眼光看世界,世界一切都是美好的;用悲伤的眼光看世界,世界一切都是痛苦的。拿一页过去,画出美丽彩虹,唱一曲未来,奏出满世光彩。

Oracle导出导入,即oracle exp/imp和expdp/impdp工具,是数据库备份恢复的一个手段。用户可以在固定时刻执行导出命令,完成数据库的备份,当数据库出现故障时,可以利用备份的数据完成导入,进而恢复数据,确保数据库的正常运行。虽然Oracle导出导入命令可以完成数据库的备份恢复,但是数据库数据量较大时,所花费的时间也大多,且导出导入恢复数据库将会导致数据丢失,故,Oracle导出导入工具也只是作为备份恢复中其中的一种手段,其中的优势及弊端用户也须考虑清楚。

一,exp/imp与expdp/impdp比较

expdp/impdp是oracle 10g中才出现的新特性,在10g之前,oracle数据库中导出导入只有exp/imp。

按照官网文档说明,expdp/impdp称为Oracle Data Pump,它不是使用常见的SQL命令,而是应用专用 API 来以更快得多的速度加载和卸载数据。导出性能比在exp模式下提高了 10 以上,导入过程性能提高了3倍以上。

1.expdp/impdp是服务端程序,exp/imp是客户端程序,exp还需要网络传输,这个很影响速度。

2.expdp/impdp读的就是数据块,exp/imp是要转换成SQL。

3.expdp/impdp可以并行导出数据、元数据和建索引、包,exp/imp不行。

4.expdp/impdp采用的是直接路径读,exp/imp是要通过SGA。

总体来说,expdp/impdp比传统exp/imp模式更快。

二、exp/imp使用(Linux环境下)

exp/imp可以在服务器上执行,也可以通过客户端连接服务器进行执行,功能强大便捷。

2.1,exp

2.1.1,参数说明

USERID 用户名和密码 FULL 是否导出所有文件

BUFFER 数据缓存大小 OWNER 用户列表

FILE 输出文件 TABLES 导出表列表

COMPRESS 表的initial尺寸(Y) RECORDLENGTH 记录长度

GRANTS 导出授权 (Y) INCTYPE incremental export type

INDEXES 导出索引 (Y) RECORD track incr. export (Y)

DIRECT 直接路径 (N) TRIGGERS 导出触发器 (Y)

LOG 导出日志文件 STATISTICS 统计信息 (ESTIMATE)

ROWS 导出数据行 (Y) PARFILE 参数文件

CONSISTENT cross-table 一致性 CONSTRAINTS 导出约束 (Y)

OBJECT_CONSISTENT 只读导出 (N)

FEEDBACK 根据设置显示导出进度 (0)

FILESIZE 导出文件的最大大小

FLASHBACK_SCN 设置SCN镜像读取点

FLASHBACK_TIME 设置时间获取接近SCN

QUERY 设置导出表条件

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.

2.1.2,基本使用

1,导出全库

exp system/123@tpc full=y file=/expdata/myfull.dmp log=myfull.log

2,导出指定用户所有信息

exp system/123@tpc owner=(tpc,test) file=/expdata/usrexp.dmp log=usrexp.log

3,导出用户下面指定表

exp tpc/123@tpc tables=tab1 file=/expdata/tab1.dmp log=tab1.log

4,导出用户结构数据,不导出表数据

exp tpc/123@tpc owner=tpc file=tpc_met.dmp log=tpc_met.log rows=n

5,按条件导出用户表数据

exp tpc/123@tpc owner=tpc tables=tab1 file=tab1_q.dmp query=\"where name=\'tpc\'\"

2.2,imp

2.2.1,参数说明

imp参数和exp参数有些许差别,这里就不一一翻译了。

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)

DATA_ONLY import only data (N)

VOLSIZE number of bytes in file on each volume of a file on tape

2.2.2,基本使用

imp导入基本上只要根据导出的文件条件进行导入即可,下面只列出几点使用方法:

1,数据有重复,加上ignore参数

imp tpc/tpc1989 file=/expdata/tab1.dmp log=imptab1.log ignore=y

2,导出文件中加入了full

imp system/123 full=y file=/expdata/myfull.dmp log=impfull.log

3,不同用户之间的导入

imp test/123 fromuser=tpc touser=test file=/expdata/tab1.dmp log=imptab1.log

三、expdp/impdp使用

3.1,directory

Directory对象是Oracle10g版本提供的一个新功能。他是一个 指向,指向了操作系统中的一个路径。每个Directory都包含 Read,Write两个权限,可以通过Grant命令授权给指定的用户或角色。拥有读写权限的用户就可以读写该Directory对象指定的操作系统路径下的文件。

1,创建directory

SQL>create directory dp_dir as '/expdata';

2,授权给用户

SQL>grant read,write on directory dp_dir to tpc;

接下来就可以使用该directory进行expdp和impdp操作了

3.2,expdp

3.2.1,参数解析

由于expdp参数解析太多,本文就不在这里一一列出来了,各位朋友可以在系统中通过expdp -help命令查看每个参数的具体说明。

3.2.2,expdp操作

1,全库导出

expdp system/123 directory=dp_dir full=y dumpfile=full.dmp logfile=full.log

2,按用户导出

expdp system/123 directory=dp_dir schemas=tpc dumpfile=tpc.dmp logfile=tpc.log

3,导出具体表

expdp system/123 directory=dp_dir tables=tpc.tab1 dumpfile=tab1.dmp logfile=tab1.log

4,查询条件导出

expdp system/123 directory=dp_dir tables=tpc.tab1 dumpfile=tab1.dmp logfile=tab1.log query=\"where name=\'tpc\'\"

5,加入并行

expdp system/123 directory=dp_dir parallel=10 schemas=tpc dumpfile=tpc.dmp logfile=tpc.log

6,表空间导出

expdp system/123 directory=dp_dir dumpfile=tabspace.dmp logfile=tabspace.log tablespaces=DT_TPC_DAT

7,传输表空间

expdp system/123 directory=dp_dir dumpfile=tablespace.dmp logfile=tablespace.log

transport_tablespaces=DT_TPC_DAT transport_full_check=y

8,此外还可以指定content参数来导出数据结构或者只是数据;include来指定要包含导出的结构等等。

3.3,impdp

3.3.1,参数解析

impdp的参数个数也太多,在这里也不一一介绍了,喜欢的朋友也可以通过impdp -help去查看相应参数说明。

3.3.2,impdp操作

1,导入数据到用户

impdp tpc/tpc1989 directory=dp_dir dumpfile=tpc.dmp logfile=imp.log schemas=tpc

2,导入整个库数据

impdp system/123 directory=dp_dir full=y dumpfile=full.dmp logfile=imp.log

3,导出和导入用户不同

impdp tpc/tpc1989 directory=dp_dir dumpfile=tpc.dmp logfile=imp.log remap_schema=test:tpc

4,替换表

impdp tpc/tpc1989 directory=dp_dir dumpfile=tpc.dmp logfile=imp.log table_exists_action=replace

5,导入表空间

impdp system/123 directory=dp_dir dumpfile=tablespace.dmp logfile=imp.log tablespaces=DT_TPC_DAT

四、概述

上述介绍基本上把oracle数据库的导入导出大部分功能介绍完成,喜欢深入研究的朋友还可以其他参数配合使用的功能,从而了解oracle导出导入的其他使用和内部原理。

  • 发表于:
  • 原文链接http://kuaibao.qq.com/s/20180119G0RJAL00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券