共计 1845 个字符,预计需要花费 5 分钟才能阅读完成。
工作中需要进行数据迁移,使用 expdp 做的,做个记录。
expdp 是 oracle10g 中提出来的,比 exp 的速度高的不是一般,这个是体验过的。和 DBA 在做数据迁移的时候,开始用的 exp,超过半个小时后,我们就忍受不了了,太慢了,就改成了 expdb,4 分钟,8 个 G,速度不错吧!
看下我们使用 脚本
1: expdp dbusername/dbpassword dumpfile=dmpfilename.dmpdirectory=DMPDIRECTORY tables=tablename:partname exclude=index;
分析一下
expdp 导出命令 dbusername/dbpassword 数据库用户名和密码(注:要有执行 expdp 命令的权利)dumpfile=dmpfilename.dmp 导出的数据文件 logfile=dmpfilelog.log 导出时的日志文件 directory=DMPDIRECTORY 数据文件的保存位置 (需要提前创建) tables=tablename:partname 按表分区导出,tablename 是表名,partname 是分区名 exclude=index 不导出索引
详细介绍下 expdp
1. 执行 expdp 之前必须创建 directory 对象,并且分配权限,如:
connect system/admin
createor replace directory expdir as'e:dmpfile';
grantread,writeon directory expdir topublic;
2. 常见用法:(我这里直接用命令行的方式,还有使用配置文件的方式)
2.1 导出 scott 整个 schema
expdp system/admin@dapengdb DIRECTORY=expdir DUMPFILE=scott_full.dmp LOGFILE=scott_full.log SCHEMAS=SCOTT
配置文件的方式
expdp system/admin@dapengdb parfile=c:exp.par
exp.par 内容:
DIRECTORY=expdir
DUMPFILE=scott_full.dmp
LOGFILE=scott_full.log
SCHEMAS=SCOTT
2.2 导出 scott 下的 dept,emp 表
expdp scott/[email protected] DIRECTORY=expdir DUMPFILE=scott.dmp LOGFILE=scott.log TABLES=DEPT,EMP
2.4 导出 scott 下的存储过程
expdp scott/tig[email protected] DIRECTORY=expdir DUMPFILE=scott.dmp LOGFILE=scott.log INCLUDE=PROCEDURE
2.5 导出 scott 下以’E’开头的表
expdp scott/tig[email protected] DIRECTORY=expdir DUMPFILE=scott.dmp LOGFILE=scott.log INCLUDE=TABLE:"LIKE'E%'" –可以改成 NOTLIKE, 就导出不以 E 开头的表
2.6 带 QUERY 导出
expdp scott/[email protected] DIRECTORY=expdir DUMPFILE=scott.dmp LOGFILE=scott.log TABLES=EMP,DEPT QUERY=EMP:"where empno >=8000″ QUERY=DEPT:"where deptno >=10 and deptno <=40″
注:处理这样带查询的多表导出,如果多表之间有外健关联,可能需要注意查询条件所筛选的数据是否符合这样的外健约束,比如:EMP 中有一栏位是 deptno,是关联 dept 中的主键,如果”where empno >=8000″中得出的 deptno=50 的话,那么,你的 dept 的条件”where deptno >=10 and deptno <=40″就不包含 deptno=50 的数据,那么在导入的时候就会出现错误! 摘抄网址:[http://www.dbifan.com/200802/common-usage-of-expdp.html](http://www.dbifan.com/200802/common-usage-of-expdp.html “http://www.dbifan.com/200802/common-usage-of-expdp.html”) 原文采用配置文件的方式。