本篇介绍一下oracle expdp导出、impdp导入的使用方法 准备工作 导出-expdp 导入-impdp 导出-expdp参数说明 导入-impdp参数说明 准备工作 oracle中的expdp导出、impdp导入的使用之前,都得先完成以下三个步骤 第一步 以管理员身份,创建逻辑目录 create direc
本篇介绍一下oracle expdp导出、impdp导入的使用方法
准备工作
导出-expdp
导入-impdp
导出-expdp参数说明
导入-impdp参数说明
准备工作
oracle中的expdp导出、impdp导入的使用之前,都得先完成以下三个步骤
第一步 以管理员身份,创建逻辑目录
create directory my_dbdata as 'd:/my_dbdata';
第二步 查看逻辑目录是否创建成功
此时应该在再查看“d:/my_dbdata”这个磁盘物理路径是否存在。因为oracle创建时并不关心该磁盘目录是否存在,如果不存在,则在后续的操作中会报错
第三步 赋予导出用户的逻辑目录操作权限
比如我要导出一个用户名为“answer”的库,则需要用管理员来赋予“answer”用户对于逻辑目录的操作权限。
grant read,write on directory my_dbdata to answer;
操作系统为windows,则打开cmd窗口,若为linux或其他unix系统,则直接在命令行操作
特别注意:在expdp、impdp命令使用时,不要习惯性的在命令末尾加上分号“;”,会导致不经意间出现错误。
曾经我进行导入操作是,最后加了个分号,语句如下:
impdp eppapp0805/eppapp0805 directory=epp_data dumpfile=eppapptest_88_20130805.dmp
remap_schema=eppapptest:eppapp0805;
看见了没,最后那个参数是remap_schema=eppapptest:eppapp0805,表示该dmp包是从eppapptest用户导出来的,要把这个dmp包导入到用户eppapp0805去,结果,导入时oracle把“eppapp0805;”连分号一起当成用户名了,一看现有库中不存在这个用户,就创建新用户,然后就创建了一个带分号结尾的用户。而这个用户还不能登录,因为有特殊字符,非常的郁闷
导出-expdp
1)按用户导出
expdp answer/answer@orcl schemas=answer dumpfile=answer.dmp directory=my_dbdata
2)按表名导出
expdp answer/answer@orcl tables=a_answer,a_question
dumpfile=m_table.dmp directory=my_dbdata
3)按查询条件导出
expdp answer/answer@orcl directory=my_dbdata dumpfile=exp_by_query.dmp
tables=a_answer query='where id < 20'
4)按表空间导出
expdp answer/answer directory=my_dbdata dumpfile=tablespace.dmp tablespaces=user
5)整个数据库导出
expdp answer/answer directory=my_dbdata dumpfile=full.dmp full=y
导入-impdp
1)导入到指定用户下
impdp answer/answer directory=my_dbdata dumpfile=answer.dmp schemas=answer
2)如果导出的用户表空间跟导入的用户表空间不一致,则按下面的方法导入
impdp answer/answer directory=my_dbdata dumpfile=answer.dmp
remap_schema=user1(导出时的所属用户名):user2(导入时的所属用户名)
3)只导入dmp文件中的某几个表
impdp answer/answer directory=my_dbdata dumpfile=answer.dmp
tables=a_answer,a_question
4)导入表空间
impdp answer/answer directory=my_dbdata dumpfile=tablespace.dmp tablespaces=user
5)导入整个数据库
impdb answer/answer directory=my_dbdata dumpfile=full.dmp full=y;
6)追加数据
impdp answer/answer directory=my_dbdata dumpfile=answer.dmp
schemas=answer table_exists_action=append
导出-expdp参数说明
content 用于指定要导出的内容,默认为all
content=all:导出对象定义和所有数据
data_only:只导出数据
metadata_only:只导出对象定义
directory
指定逻辑目录的名称,为之前创建的逻辑目录。
exclude
用于指定执行操作时释放要排除的对象类型或相关对象
exclude=object_type[:name_clause] [,….]
object_type用于指定要排除的对象类型,name_clause用于指定要排除的具体对象
例:exclude=table:emp
exclude和include不能同时使用
include
导出时包含指定的类型
例:include=table_data,
include=table:like 'tab%'
include=table:”not like ‘tab%’”…
exclude和include不能同时使用
filesize
指定导出文件的大小,默认为0,表示没有大小限制(单位为bytes)
tablespace
指定一个表空间导出
query
query=[schema.]
[table_name:] query_clause
schema为指定方案名,table_name为指定表名,query_clause用于指定条件限制子句
例:expdp answer/answer directory=my_dbdata dumpfiel=answer.dmp tables=a_answer query=’where deptno=20’
query选项不能与connect=metadata_only,extimate_only,transport_tablespaces等选项同时使用.
parallel
并行操作:指定执行导出操作的并行进程个数,默认值为1
您可以通过parallel
参数为导出使用一个以上的线程加速作业。每个线程创建一个单独的转储文件,因此参数dumpfile
应当拥有和并行度一样多的项目。您可以指定通配符作为文件名,而不是显式地输入各个文件名,
例:expdp answer/answer tables=a_answer directory=my_dbdata dumpfile=expcases_%u.dmp parallel=4
注意:dumpfile
参数拥有一个通配符%u,它指示文件将按需要创建,格式将为expcases_nn.dmp,其中nn 从01 开始,然后按需要向上增加。
在并行模式下,状态屏幕将显示四个工作进程。(在默认模式下,只有一个进程是可见的)所有的工作进程同步取出数据,并在状态屏幕上显示它们的进度。
分离访问数据文件和转储目录文件系统的输入/输出通道是很重要的。否则,与维护data
pump 作业相关的开销可能超过并行线程的效益,并因此而降低性能。并行方式只有在表的数量多于并行值并且表很大时才是有效的。
导入-impdp参数说明
tabble_exists_action
tabble_exists_action={skip
| append | truncate | frplace }
skip:导入时会跳过已存在的对象
append:导入时会追加数据
truncate:导入时会截断表,然后追加新的数据
replace:导入时会删除已存在的表,重建表再追加数据
remap_schema
用于将源方案中的所有对象装载到目标方案中。
例:如果dmp文件导出时对应用户名为 user1,
导入时对应用户名为user2,
则因为用户名不一致而无法导入,需要这样用
remap_schema=user1:user2
remap_tablespace
将源表空间的所有对象导入到目标表空间
remap_tablespace=source_tablespace:target:tablespace
remap_datafile
将源数据文件转变为目标数据文件,在不同平台之间搬移表空间可能需要该选项
remap_datafiel=source_datafie:target_datafile