当前位置:网站首页>ORACLE进阶(一) 通过EXPDP IMPDP命令实现导dmp
ORACLE进阶(一) 通过EXPDP IMPDP命令实现导dmp
2022-07-03 10:24:00 【InfoQ】
一、前言
dmpdmporacle二、准备工具
- FileZilla
- SecureCRT
FileZilladmpSecureCRT三、Expdp文件导出
dmpDIRECTORY指定转储文件和日志文件所在的目录。
DIRECTORY=directory_object
Directory_objectCREATE DIRECTORYOSExpdp scott/tiger DIRECTORY= DMP DUMPFILE=a.dump
create or replace directory dmp as 'd:/dmp'
expdp zftang/zftang(@zftang) directory=dmp dumpfile=test.dmp content=metadata_only
CONTENT该选项用于指定要导出的内容。默认值为ALL。
CONTENT={ALL | DATA_ONLY | METADATA_ONLY}
CONTENTALLDATA_ONLYMETADATA_ONLYexpdp zftang/[email protected] directory=dmp dumpfile=test.dmp content=metadata_only
expdp zftang/[email protected] directory=dmp dumpfile=test.dmp content=data_only
DUMPFILE用于指定转储文件的名称,默认名称为expdat.dmp。
DUMPFILE=[directory_object:]file_name [,….]
Directory_objectfile_namedirectory_objectDIRECTORYexpdp zftang/[email protected] directory=dmp dumpfile=test1.dmp
DIRECTORYcreate directory dir_dp as 'D:/oracle/dir_dp';
Grant read,write on directory dir_dp to zftang;
SELECT privilege, directory_name, DIRECTORY_PATH FROM user_tab_privs t, all_directories d WHERE t.table_name(+) = d.directory_name ORDER BY 2, 1;
expdp zftang/[email protected] schemas=zftang directory=dir_dp dumpfile =expdp_test1.dmp logfile=expdp_test1.log;
Oracle Database 10g Enterprise Edition Release 10.2.0.1四、备注
directory=dir_dpORA-39002: 操作无效
ORA-39070: 无法打开日志文件。
ORA-39087: 目录名DATA_PUMP_DIR; 无效2、在导出过程中,DATA DUMP创建并使用了一个名为SYS_EXPORT_TABLE_01的对象,此对象就是DATA DUMP导出过程中所用的JOB名字,如果在执行这个命令时如果没有指定导出的JOB名字那么就会产生一个默认的JOB名字,如果在导出过程中指定JOB名字就为以指定名字出现。
expdp zftang/[email protected] schemas=zftang directory=dir_dp dumpfile =expdp_test1.dmp logfile=expdp_test1.log,job_name=my_job1;
jobexpdp zftang/zftang attach=zftang.my_job1五、数据泵导出的各种模式
5.1 按表模式导出:
expdp zftang/[email protected] tables=zftang.b$i_exch_info,zftang.b$i_manhole_info dumpfile
=expdp_test2.dmp logfile=expdp_test2.log directory=dir_dp
job_name=my_job
5.2 按查询条件导出
expdp zftang/[email protected] tables=zftang.b$i_exch_info dumpfile =expdp_test3.dmp logfile=expdp_test3.log directory=dir_dp job_name=my_job query='"where rownum<11"'
5.3 按表空间导出
Expdp zftang/[email protected] dumpfile=expdp_tablespace.dmp tablespaces=GCOMM.DBF logfile=expdp_tablespace.log directory=dir_dp job_name=my_job
5.4 导出方案
Expdp zftang/zftang DIRECTORY=dir_dp DUMPFILE=schema.dmp SCHEMAS=zftang,gwm
5.5 导出整个数据库
expdp zftang/[email protected] dumpfile =full.dmp full=y logfile=full.log directory=dir_dp job_name=my_job
六、Impdp文件导入
6.1 按表导入
impdp gwm/[email protected] dumpfile =p_street_area.dmp
logfile=imp_p_street_area.log directory=dir_dp tables=p_street_area
job_name=my_job
6.2 按用户导入(可以将用户信息直接导入,即如果用户信息不存在的情况下也可以直接导入)
impdp gwm/[email protected] schemas=gwm dumpfile =expdp_test.dmp logfile=expdp_test.log directory=dir_dp job_name=my_job
6.3 不通过expdp的步骤生成dmp文件而直接导入的方法
--从源数据库中向目标数据库导入表p_street_area
impdp gwm/gwm directory=dir_dp NETWORK_LINK=igisdb tables=p_street_area logfile=p_street_area.log job_name=my_job
igisdb是目的数据库与源数据的链接名,dir_dp是目的数据库上的目录
6.4 更换表空间
remap_tablespace--导出gwm用户下的所有数据
expdp system/orcl directory=data_pump_dir dumpfile=gwm.dmp SCHEMAS=gwm
sysimpdp system/orcl directory=data_pump_dir dumpfile=gwm.dmp remap_tablespace=gmapdata:gcom
七、EXP、IMP与EXPDP、IMPDP的区别
EXP和IMP是客户端工具程序,它们既可以在客户端使用,也可以在服务端使用。
EXPDP和IMPDP是服务端的工具程序,他们只能在ORACLE服务端使用,不能在客户端使用。
IMP只适用于EXP导出的文件,不适用于EXPDP导出文件;IMPDP只适用于EXPDP导出的文件,而不适用于EXP导出文件。
expdp或impdp命令时,可暂不指出用户名/密码@实例名 as 身份,然后根据提示再输入,如:
expdp schemas=scott dumpfile=expdp.dmp DIRECTORY=dpdata1;
八、导出导入可能遇到的坎
8.1中文字符集转换
- KUP-11007:
conversion error loading table "TEST"."T_PSR" ORA-12899:列REASON_CODE 的值太大 (实际值: 21, 最大值: 20)
- KUP-11009:
data for row: REASON_CODE : 0X'BABDBFD5C6F7C8DDC1BFCFDED6C6'
8.2 主外键关联
- ORA-31693:
Table data object "TEST"."T_ITE" failed to load/unload and is being skipped due to error:
- ORA-29913:
error in executing ODCIEXTTABLEFETCH callout
- ORA-02291:
integrity constraint (TEST.FK_ITE_REF_PSR) violated parent key not found
- 导入前,执行如下SQL找到需要禁止的外键关联
select 'ALTER TABLE '||TABLE_NAME||' DISABLE CONSTRAINT '||constraint_name||';'from user_constraints WHERE
CONSTRAINT_TYPE='R';
- 执行(a)的结果SQL。
- 导入后,执行如下SQL找到需要恢复的外键关联
select 'ALTER TABLE '||TABLE_NAME||' ENABLE NOVALIDATE CONSTRAINT '||constraint_name||';' from user_constraints WHERE
CONSTRAINT_TYPE='R';
NOVALIDATE九、总结
- 使用10g以上版本提供的expdp/impdp数据泵导入导出工具,较以往的exp/imp工具,无论是在参数的可选择性上,还是速度和压缩比上,都有了不小的改进,提供更为方便快速的数据导入导出方法给我们。
- 导入导出可能碰到最多的问题,字符集转换算是其中之一,要明确导入导出数据对字符集的依赖程度,才能确保数据导入导出的正确。
- 对于有主外键关联的数据,如果选择data_only仅导出数据,那么可在导入前禁止约束,这样导入过程不会受到主外键关联的影响,导入后可以恢复约束,保证约束的正确。
十、删除外键约束
ALTER TABLE test_sub DROP CONSTRAINT main_id_cons;
constraint_type='R'alter table table_name enable constraint constraint_namealter table table_name disable constraint constraint_nameselect 'alter table '||table_name||' enable constraint '||constraint_name||';' from user_constraints where constraint_type='R'
边栏推荐
- Google Earth Engine(GEE)——当我们前后影像来弥补插值效果得时候,没有效果怎么办?
- Illustrated network: what is virtual router redundancy protocol VRRP?
- Application of high-precision indoor positioning technology in safety management of smart factory
- AIDL
- Crawl with requests
- 用了这么久线程池,你真的知道如何合理配置线程数吗?
- 一文搞懂Go语言Context
- Kotlin's use of the no Arg compiler plug-in in gradle
- Processes and threads
- 线性表顺序表综合应用题P18
猜你喜欢

Summary of interview questions (2) IO model, set, NiO principle, cache penetration, breakdown avalanche

A simple method of adding dividing lines in recyclerview

Processes and threads

软件测试周刊(第78期):你对未来越有信心,你对现在越有耐心。

(二)进制

Intel 13th generation core flagship exposure, single core 5.5ghz

Event preview | the live broadcast industry "rolled in" to drive new data growth points with product power

00后抛弃互联网: 毕业不想进大厂,要去搞最潮Web3

The element form shows the relationship between elementary transformation and elementary matrix

Crawl with requests
随机推荐
程序进程管理工具-go supervisor
Internet socket (non) blocking write/read n bytes
Using onvif protocol to operate the device
VPP三层网络互联配置
Unique in the industry! Fada electronic contract is on the list of 36 krypton hard core technology enterprises
CorelDRAW Graphics Suite 2022新版功能详情介绍
.\vmware-vdiskmanager.exe -k “c:\\xxxxx.vmdk”
如何成为一名高级数字 IC 设计工程师(1-3)Verilog 编码语法篇:Verilog 行为级、寄存器传输级、门级(抽象级别)
IIS does not take effect after modifying the configuration information
Analysis of JMM memory model
(2) Base
[VTK] vtkPolydataToImageStencil 源码解读
Unity移动端游戏性能优化简谱之 画面表现与GPU压力的权衡
Ext file system mechanism principle
After a month, I finally got Kingdee offer! Share tetrahedral Sutra + review materials
Incremental database backup - DB incr DB full
(二)进制
Gut | Yu Jun group of the Chinese University of Hong Kong revealed that smoking changes intestinal flora and promotes colorectal cancer (do not smoke)
[OBS] configFile in ini format of OBS
基于I2C协议的驱动开发