当前位置:网站首页>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)——GHSL 全球人口网格数据集250米分辨率
- 封装一个koa分布式锁中间件来解决幂等或重复请求的问题
- LeetCode 46:全排列
- 线性表的双链表
- VPP three-layer network interconnection configuration
- Project management essence reading notes (6)
- 解决undefined reference to `__aeabi_uidivmod‘和undefined reference to `__aeabi_uidiv‘错误
- (2) Base
- Tablespace creation management and control file management
- Using onvif protocol to operate the device
猜你喜欢

活动预告 | 直播行业“内卷”,以产品力拉动新的数据增长点

FL Studio 20 unlimited trial fruit arranger Download

MATLAB提取不規則txt文件中的數值數據(簡單且實用)

After a month, I finally got Kingdee offer! Share tetrahedral Sutra + review materials

Driver development based on I2C protocol

MATLAB extrait les données numériques d'un fichier txt irrégulier (simple et pratique)

Encapsulate a koa distributed locking middleware to solve the problem of idempotent or repeated requests

Google Earth engine (GEE) - ghsl global population grid dataset 250 meter resolution

解决undefined reference to `__aeabi_uidivmod‘和undefined reference to `__aeabi_uidiv‘错误

Stack, monotone stack, queue, monotone queue
随机推荐
Event preview | the live broadcast industry "rolled in" to drive new data growth points with product power
Multi dimensional monitoring: the data base of intelligent monitoring
Illustrated network: what is virtual router redundancy protocol VRRP?
2. Hal hardware abstraction layer
Cuiyusong, CTO of youzan: the core goal of Jarvis is to make products smarter and more reliable
Oracle收回权限 & 创建角色
软考中级软件设计师该怎么备考
Gut | 香港中文大学于君组揭示吸烟改变肠道菌群并促进结直肠癌(不要吸烟)
Driver development based on I2C protocol
C语言二维数组
有赞CTO崔玉松:有赞Jarvis核心目标是使产品变得更加聪明和可靠
Unique in the industry! Fada electronic contract is on the list of 36 krypton hard core technology enterprises
Tencent micro app to get wechat user information
英特尔13代酷睿旗舰曝光,单核5.5GHz
Gut | Yu Jun group of the Chinese University of Hong Kong revealed that smoking changes intestinal flora and promotes colorectal cancer (do not smoke)
Google Earth Engine(GEE)——GHSL 全球人口网格数据集250米分辨率
CSRF
大厂技术专家:工程师如何提升沟通能力?
线性表的双链表
MATLAB提取不規則txt文件中的數值數據(簡單且實用)