Linux版Oracle数据库19C expdp/impdp 导入导出数据

数据无价,请在重要操作之前备份数据,防止意外造成数据丢失

设置数据库虚拟路径

1.创建文件夹(服务器中执行)

mkdir /home/oracle/dmp

2.路径创建后授权(服务器中执行)

chown -R oracle /home/oracle/dmp

3.创建dmp导入导出的虚拟文件路径(数据库中执行)

create or replace directory DMPDATA as '/home/oracle/dmp'

4.对用户进行授权,否则用户导入导出时会报ORA-39087: directory name DMPDATA is invalid(数据库中执行)

grant read,write on directory DMPDATA to username

导出

服务器中执行,expdp未设置环境变量的话,需要进/opt/oracle/product/19c/dbhome_1/bin路径下执行,具体路径根据数据库安装的位置及版本会有变化
除导出指定表外,其余方式只能导出当前用户下默认表空间的表,其他表空间的表无法导出

导出全部的表

DMPDATA为数据库虚拟路径,user为数据库用户名,password为用户密码

expdp user/password directory=DMPDATA dumpfile=dmp_full.dmp FULL=y logfile=expdp_dmp_full.log

导出指定用户

DMPDATA为数据库虚拟路径,user为数据库用户名,password为用户密码,userA,userB为导出的用户名,多用户之间使用,分割

expdp user/password directory=DMPDATA dumpfile=dmp_user.dmp logfile=expdp_dmp_user.log schemas=userA,userB

导出指定表空间

DMPDATA为数据库虚拟路径,user为数据库用户名,password为用户密码,tablespacesA为导出的指定表空间,多个表空间之间使用,分割

expdp user/password directory=DMPDATA dumpfile=dmp_spaces.dmp logfile=expdp_dmp_spaces.log tablespaces=tablespacesA,tablespacesB

导出指定表

DMPDATA为数据库虚拟路径,user为数据库用户名,password为用户密码,tableA,tableB为导出的指定的表,多个表之间使用,分割

expdp user/password directory=DMPDATA dumpfile=dmp_tb.dmp logfile=expdp_dmp_tb.log tables=tableA,tableB

导出时排除指定表

DMPDATA为数据库虚拟路径,user为数据库用户名,password为用户密码,排除表时需要用反斜线进行转义

expdp user/password directory=DMPDATA dumpfile=dmp_tb.dmp logfile=dmp_tb.log exclude=table:\"in\(\'SYS_LOG\',\'SYSTEM_LOG\'\)\"

如果排除的表不存在时会失败报错信息为ORA-31655: 尚未为作业选择数据或元数据对象

按照查询条件导出,需指定具体的表

DMPDATA为数据库虚拟路径,user为数据库用户名,password为用户密码,tableA为导出的指定的表,query后面是查询条件

expdp user/password directory=DMPDATA dumpfile=dmp_select.dmp logfile=expdp_dmp_select.log tables=tableA query='WHERE ID > 1 AND ID <10'

导出指定数据库版本的dmp

  • 使用version属性指定具体版本
  • 适用于高版本导出,低版本导入的场景
expdp user/password directory=DMPDATA dumpfile=dmp_full.dmp FULL=y logfile=expdp_dmp_full.log version=11.2.0.1.0

导入

服务器中执行,impdp未设置环境变量的话,需要进/opt/oracle/product/19c/dbhome_1/bin路径下执行,具体路径根据数据库安装的位置及版本会有变化

导入全库表

DMPDATA为数据库虚拟路径,user为数据库用户名,password为用户密码

impdp user/password directory=DMPDATA DUMPFILE=dmp_full.dmp FULL=y logfile=impdp_dmp_full.log table_exists_action=replace

按用户导入

DMPDATA为数据库虚拟路径,user为数据库用户名,password为用户密码,userA,userB为导出的用户名,多用户之间使用,分割

impdp user/password directory=DMPDATA dumpfile=dmp_user.dmp logfile=impdp_dmp_user.log schemas=userA,userB table_exists_action=replace

按表空间导入

DMPDATA为数据库虚拟路径,user为数据库用户名,password为用户密码,tablespacesA为导出的指定表空间,多个表空间之间使用,分割

impdp user/password directory=DMPDATA dumpfile=dmp_spaces.dmp logfile=impdp_dmp_spaces.log tablespaces=tablespacesA,tablespacesB table_exists_action=replace

按表导入

DMPDATA为数据库虚拟路径,user为数据库用户名,password为用户密码,tableA,tableB为表名,多个表之间使用,分割

impdp user/password directory=DMPDATA dumpfile=dmp_tb.dmp logfile=impdp_dmp_tb.log tables=tableA,tableB table_exists_action=replace

按照查询条件导入

DMPDATA为数据库虚拟路径,user为数据库用户名,password为用户密码,tableA为表名,query为条件

impdp user/password directory=DMPDATA dumpfile=dmp_select.dmp logfile=impdp_dmp_select.log tables=tableA query='WHERE ID > 1 AND ID <10' table_exists_action=replace

table_exists_action参数说明

  • skip是如果已存在表,则跳过并处理下一个对象;
  • append是为表增加数据;
  • truncate是截断表,然后为其增加新数据;
  • replace是删除已存在表,重新建表并追加数据

导入时所用的用户名或者表空间与导出时的用户名或者表空间不一致解决办法

用户名不一致

使用remap_schema 更改用户名

remap_schema = 导出时的用户名:导入时的用户名

表空间不一致

使用remap_tablespace 更改表空间

remap_tablespace = 导出时的表空间:导入时的表空间
© 版权声明
THE END
喜欢就支持一下吧
点赞2打赏 分享
评论 共1条

请登录后发表评论