当前位置:网站首页>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'
边栏推荐
猜你喜欢

C语言 AES加解密

Application of high-precision indoor positioning technology in safety management of smart factory

反正切熵(Arctangent entropy):2022.7月最新SCI论文

Crawl with requests

Abandon the Internet after 00: don't want to enter a big factory after graduation, but go to the most fashionable Web3

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

How to clean up v$rman_ backup_ job_ Details view reports error ora-02030

Multi dimensional monitoring: the data base of intelligent monitoring

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

The five-year itch of software testing engineers tells the experience of breaking through bottlenecks for two years
随机推荐
A simple method of adding dividing lines in recyclerview
AMS series - application startup process
CSRF
CSRF
一文搞懂Go语言Context
How to become a senior digital IC Design Engineer (1-5) Verilog coding syntax: operand
大厂技术专家:工程师如何提升沟通能力?
Project management essence reading notes (VII)
浅析-JMM内存模型
用了这么久线程池,你真的知道如何合理配置线程数吗?
POI excel cell wrap
软考中级软件设计师该怎么备考
帝国cms 无缩略图 灵动标签(e:loop)判断有无标题图片(titlepic)的两种写法
Gut | Yu Jun group of the Chinese University of Hong Kong revealed that smoking changes intestinal flora and promotes colorectal cancer (do not smoke)
今晚要修稿子準備發佈。但是,仍卡在這裡,也許你需要的是一個段子。
程序进程管理工具-go supervisor
线性表顺序表综合应用题P18
解决undefined reference to `__aeabi_uidivmod‘和undefined reference to `__aeabi_uidiv‘错误
php如何解决高并发问题
2. Hal hardware abstraction layer