专业编程教程与实战项目分享平台

网站首页 > 技术文章 正文

超实用的Oracle数据泵导出导入:impdp实际案例分享

ins518 2024-10-16 12:23:57 技术文章 12 ℃ 0 评论

概述

继上篇expdp导出,这里主要分享怎么去用impdp命令。


1. 首先需要创建Directory

这里目录名字定义为"jy",

若是windows平台,对应系统目录为"E:\jingyu";

create or replace directory jy as 'E:\jingyu';

若是Unix/Linux平台,对应系统目录为"/tmp/jingyu".

create or replace directory jy as '/tmp/jingyu';

注意:目录在系统上需要真实存在(mkdir -p /tmp/jingyu),且有访问的权限。

2. 创建表空间和用户及赋权

create tablespace users datafile '+data1' size 10M autoextend on maxsize 30G;
create user scott identified by tiger default tablespace users;
grant connect, resource to scott;
grant read, write on directory jy to scott;

3. 使用impdp导入用户数据

初始化环境:

初始1:得到删除当前用户下表的SQL:select 'drop table '||table_name||' purge;' from user_tables;

初始2:得到查询当前用户下表的数据量:select 'select count(1) from '||table_name||';' from user_tables;

3.1 导入scott用户的元数据,且不包含统计信息;

impdp system directory=jy dumpfile=scott_meta.dmp logfile=impdp_scott_meta.log

3.2 导入scott用户的数据;

在3.1导入元数据后才可以导入数据。

impdp system directory=jy dumpfile=scott_data.dmp logfile=impdp_scott_data.log

3.3 只导入scott用户下的emp表及数据;

这里为了演示导入,先初始化删除scott用户下的所有表。

impdp scott directory=jy tables=emp dumpfile=scott_emp_dept.dmp logfile=impdp_scott_emp.log

3.4 只导入scott用户下的emp,dept表结构;

这里为了演示导入,先初始化删除scott用户下的所有表。

impdp scott directory=jy tables=emp,dept dumpfile=scott_emp_dept_meta.dmp logfile=impdp_scott_emp_dept_meta.log

由于导出就是emp,dept两张表,所以也可以不指定tables,以下两种写法在这里都是可以的:

impdp scott directory=jy dumpfile=scott_emp_dept_meta.dmp logfile=impdp_scott_emp_dept_meta.log
impdp scott directory=jy dumpfile=scott_emp_dept_meta.dmp logfile=impdp_scott_emp_dept_meta.log full=y

3.5 并行导入scott用户下所有的内容;

impdp system directory=jy schemas=scott table_exists_action=replace dumpfile=scott_all%U.dmp logfile=impdp_scott_all.log parallel=2

这里对于已经存在的对象直接replace掉。


总结

到这里关于expdp和impdp就告一段落啦,在工作中这个还是很实用的,而且会碰到各种奇怪的问题,例如expdp导出时显示乱码、导入时提示用户不存在等等,这种就要靠大家多多尝试了。

后面会分享更多关于DBA内容,感兴趣的朋友可以关注下!!

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表