cmd imp导入dmp文件_exp/imp、expdp/impdp使用总结,这些你都清楚吗?

Oracle备份分成物理备份与逻辑备份。

物理备份: 把实际物理文件从一处拷贝到另一处(可能是原样拷贝,也可能经过压缩), 操作系统备份,使用RMAN的备份,冷备份,热备份。

逻辑备份: 利用SQL从数据库中提取数据,并将其保存到文件中,这些数据可以在以后需求时重新导入数据库,或者导入其他数据库。Oracle提供EXP, IMP, EXPDP, IMPDP工具。

下面就介绍一下 EXP, IMP, EXPDP, IMPDP工具 的大概用法以及工作中遇到的一些坑。

【用exp数据导出】:

1 将数据库TEST完全导出,用户名system 密码manager 导出到D:daochu.dmp中

exp system/manager@TEST rows=y indexes=y compress=n buffer=65536 feedback=100000full=y file=d:daochu.dmp log=d:daochulog.txt owner=(ECC_BIZ,ECC_CUSTOMER)

ac506ef4942f934815daf64d969a424e.png

参数说明

db8056fb1365d282deadfde2ba1e66b5.png

参数说明

2 将数据库中system用户与sys用户的表导出

exp system/manager@TEST file=d:daochu.dmp owner=(system,sys)

3 将数据库中的表table1 、table2导出

exp system/manager@TEST file=d:daochu.dmp tables=(table1,table2)

4 将数据库中的表table1中的字段filed1以”00″打头的数据导出

exp system/manager@TEST file=d:daochu.dmp tables=(table1) query=” where filed1like '00%'”

上面是常用的导出,对于压缩我不太在意,用winzip把dmp文件可以很好的压缩。不过在上面命令后面 加上 compress=y 就可以了。

【用imp数据导入】:

1 将D:daochu.dmp 中的数据导入 TEST数据库中。

imp system/manager@TEST ignore=y full=y file=d:daochu.dmp log=d:daoru.txt

66de6167b1531e7a60beecce1401ea54.png

imp参数说明

2d70fba90118f9ae6329e8f8154ab0e9.png

imp参数说明

69e723899fdf798f79dd715b8c48a24e.png

imp参数说明

1. 获取帮助

imp help=y

2. 导入一个完整数据库

imp system/manager file=bible_db log=dible_db full=y ignore=y

3. 导入一个或一组指定用户所属的全部表、索引和其他对象

imp system/manager file=seapark log=seapark fromuser=seapark

imp system/manager file=seapark log=seapark fromuser=(seapark,amy,amyc,harold)

4. 将一个用户所属的数据导入另一个用户

imp system/manager file=tank log=tank fromuser=seapark touser=seapark_copy

imp system/manager file=tank log=tank fromuser=(seapark,amy) touser=(seapark1, amy1)

5. 导入一个表

imp system/manager file=tank log=tank fromuser=seapark TABLES=(a,b)

6. 从多个文件导入

imp system/manager file=(paycheck_1,paycheck_2,paycheck_3,paycheck_4) log=paycheck,filesize=1G full=y

7. 使用参数文件

imp system/manager parfile=bible_tables.par

bible_tables.par参数文件:

#Import the sample tables used for the Oracle8i Database Administrator's

#Bible.

fromuser=seapark touser=seapark_copy file=seapark log=seapark_import

8. 增量导入(9i中已经取消)

imp system./manager inctype= RECTORE FULL=Y FILE=A

远程exp导出数据:

exp username/password@ip/sid direct=y rows=y buffer=9999999 constraints=y grants=n triggers=n STATISTICS=none file=xxx.dmp log=xxx.log tables=owner.table_name

imp导入数据:

imp username/password@ip/sid file=xxx.dmp log=xxx.log full=n ignore=y buffer=100000000 commit=y fromuser=fuser touser=tuser

【用expdp数据导出】:

创建逻辑目录

create directory mydir as '/data/oracle/oradata/mydata';

查看逻辑目录是否创建成功

select * from dba_directories where directory_name='mydir'

expdp导出数据

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

注:ip缺省值为本机

expdp具体用法:

1)导出用户及其对象

expdp a/b@orcl schemas=c dumpfile=d.dmp directory=mydir logfile=d.log;

2)导出指定表

expdp a/b@orcl tables=t,t2 dumpfile=d.dmp directory=mydir logfile=d.log;

3)按查询条件导

expdp a/b@orcl directory=mydir dumpfile=d.dmp tables=t query='where g=0' logfile=d.log;

4)按表空间导

expdp a/b@orcl directory=mydir dumpfile=tablespace.dmp tablespaces=ts,ts2 logfile=d.log;

5)导整个数据库

expdp a/b@ip/orcl directory=mydir dumpfile=d.dmp full=y logfile=d.log;

常用属性:

directory=dmpfile --导出的逻辑目录,一定要在oracle中创建完成的,并且给用户授权读写权限

schemas=s --使用dblink导出的用户不是本地的用户,需要加上schema来确定导出的用户,类似于exp中的owner,但还有一定的区别

EXCLUDE=TABLE:"IN('T1','T2','T3')" --exclude 可以指定不导出的东西,table,index等,后面加上不想导出的表名

network_link=db_local --这个参数是使用的dblink来远程导出,需要指定dblink的名称

【用impdp数据导入】:

导入之前先检查导入的用户是否存在,用户权限及用户表空间是否够。若是一个新用户,则可以自行创建表空间和用户(一般需要dba权限):

create tablespace data_are datafile 'd:oracleoradataabca.dbf' size 20G;

create user s identified by b default tablespace data_are;

给用户逻辑目录读写权限

grant read,write on directory mydir to s;

给用户表空间权限

grant dba,resource,unlimited tablespace to s;

impdp导入

1)导入用户(从用户a导入到用户s)

impdp s/b@orcl directory=mydir dumpfile=d.dmp schemas=s logfile=b.log;

2)导入表(从a用户中把表dept和emp导入到p用户中)

impdp s/b@orcl directory=mydir dumpfile=d.dmp tables=a.dept,a.emp remap_schema=a:s logfile=d.log table_exists_action=replace ;

注:参数 table_exists_action:表空间已存在则替换

3)导入表空间

impdp s/b@orcl directory=mydir dumpfile=ts.dmp tablespaces=data_are logfile=d.log;

4)导入整个数据库

impdb s/b@orcl directory=mydir dumpfile=d.dmp full=y logfile=d.log;

5)加数据

impdp s/b@orcl directory=mydir dumpfile=d.dmp schemas=s table_exists_action==replace logfile=d.log;

遇到的问题和解决方法:

1。工作中经常遇到要把某些表导入到另外一个数据库的另一个用户中,导出的表空间和导入的表空间不一致,所以直接导入的时候一般都会报错。

使用imp导入时:

1)需手动创建表结构。

2)imp的时候加ignore=y 参数导入。

有一种说法是11g之前imp支持tablespace参数,可以指定表空间,11g及之后取消了这个参数,待验证。

使用impdp导入时:

1)使用参数remap_tablespace指定表空间即可。

2。源数据库和目标数据库版本不一致导致导入时报错。

1)有人说直接编辑dmp文件,修改版本为目标数据库的版本,但是发现改了以后导入的时候还是报错,不知道是不是姿势不对。

2)可以在目标数据库服务器上远程exp导出dmp文件,然后再imp导入,就不存在版本差异问题了。

关注+评论+转发

工作中的一些总结,希望大家一起学习,一起进步。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值