关于expdp/impdp的简单数据泵导入导出命令

EXPDP数据导出

请自行修改目录路径和自定义的表名,否则出现错误很难查找~

一般expdp流程:
在这里插入图片描述

一、新建逻辑目录

最好以system等管理员创建逻辑目录,Oracle不会自动创建实际的物理目录“D:\oracleData”(务必手动创建此目录),仅仅是进行定义逻辑路径dump_dir

建议使用pl、navicat等oracle操作工具来操作;

登陆后sql执行:

create directory mydata as '逻辑目录路径'; 
例如: 
create directory mydata as '/data/oracle/oradata/mydata';
二、查看逻辑目录是否创建成功
执行sqlsql>select * from dba_directories

在这里插入图片描述

三、用expdp导出数据

用法及解释:

expdp 用户名/密码@ip地址/实例 [属性]
ip地址不写默认就是本地

userid=test/test --导出的用户,本地用户!!
directory=dmpfile --导出的逻辑目录,一定要在oracle中创建完成的,并且给用户授权读写权限
dumpfile=xx.dmp --导出的数据文件的名称,如果想在指定的位置的话可以写成dumpfile=/home/oracle/userxx.dmp
logfile=xx.log --日志文件,如果不写这个参数的话默认名称就是export.log,可以在本地的文件夹中找到
schemas=userxx --使用dblink导出的用户不是本地的用户,需要加上schema来确定导出的用户,类似于exp中的owner,但还有一定的区别
EXCLUDE=TABLE:“IN(‘T1’,‘T2’,‘T3’)” --exclude 可以指定不导出的东西,table,index等,后面加上不想导出的表名
network_link=db_local --这个参数是使用的dblink来远程导出,需要指定dblink的名称

列出一些场景:

1)导出用户及其对象
expdp scott/tiger@orcl schemas=scott dumpfile=expdp.dmp directory=dump_dir logfile=expdp.log;

2)导出指定表
expdp scott/tiger@orcl tables=emp,dept dumpfile=expdp.dmp directory=dump_dir logfile=expdp.log;

3)按查询条件导
expdp scott/tiger@orcl directory=dump_dir dumpfile=expdp.dmp tables=empquery=‘where deptno=20’ logfile=expdp.log;

4)按表空间导
expdp system/manager@orcl directory=dump_dir dumpfile=tablespace.dmp tablespaces=temp,example logfile=expdp.log;

5)导整个数据库
expdp scott/123@127.0.0.1/orcl directory=dump_dir dumpfile=ly.dmp full=y logfile=expdp.log;

一般用的都是导出整个数据库,本人使用的代码:

   包含所有用户的表、视图、索引等
    expdp JCPT/123@127.0.0.1/orcl directory=mydata dumpfile=ly.dmp full=y  logfile=expdp.log;
   指定用户的表、视图、索引等
    expdp JCPT/123@127.0.0.1/orcl directory=mydata schemas=jcpt dumpfile=ly.dmp logfile=expdp.log;

导出完成后:逻辑目录生成了一个 dmp文件;
在这里插入图片描述

IMPDP数据导入

在正式导入数据前,要先确保要导入的用户已存在,如果没有存在,请先用下述命令进行新建用户

流程:
在这里插入图片描述

一、创建表空间

使用system登录oracle,执行sql

格式: create tablespace 表间名 datafile ‘数据文件名’ size 表空间大小

   create tablespace data_test datafile 'e:\oracle\oradata\test\test.dbf' size 2000M;
                    (*数据文件名 包含全路径, 表空间大小 2000M 表是 2000) 
二、创建用户并授权

格式: create user 用户名 identified by 密码 default tablespace 表空间表;

create user study identified by study default tablespace data_test;

(*我们创建一个用户名为 study,密码为 study, 表空间为 madate-这是在上一步建好的.)

授权给 用户 study ,执行sql

   给用户逻辑目录读写权限
    sql>grant read,write on directory mydata to study;
   给用户表空间权限
    sql>grant dba,resource,unlimited tablespace to study;
三、impdp导入

命令在cmd或者控制台输入,不是sql语句

写法:

impdp 用户名/密码@ip地址/实例 [属性]

ip地址不写默认就是本地

注释:

1)导入用户(从用户scott导入到用户scott)
impdp scott/tiger@orcl directory=dump_dir dumpfile=expdp.dmp schemas=scott logfile=impdp.log;

2)导入表(从scott用户中把表dept和emp导入到system用户中)
impdp system/manager@orcl directory=dump_dir dumpfile=expdp.dmp tables=scott.dept,scott.emp remap_schema=scott:system logfile=impdp.log table_exists_action=replace (表空间已存在则替换);

3)导入表空间
impdp system/manager@orcl directory=dump_dir dumpfile=tablespace.dmp tablespaces=example logfile=impdp.log;

4)导入整个数据库
impdb system/manager@orcl directory=dump_dir dumpfile=full.dmp full=y logfile=impdp.log;

日常使用的:

   把用户jcpt中所有的表导入到lyxt用户下
 impdp lyxt/lyxt123@127.0.0.1/orcl directory=mydata dumpfile=LY.DMP remap_schema=jcpt:lyxt logfile=ims20171122.log table_exists_action=replace

5)追加数据

impdp system/manager@orcl directory=dump_dir dumpfile=expdp.dmp schemas=systemtable_exists_action logfile=impdp.log;
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值