ORACLE 通过IMPDP导入DMP文件时更改用户及表空间方法

impdp默认导入expdp的dmp文件时,是需要建立相同名称的表空间及临时表空间的;而且会自动创建相同名称的用户名。

但是有时候我们想更改这种默认设置,这个时候就要用到impdp的特殊参数remap_schema(更改用户名)及remap_tablespace(更改存储表空间);

假设我们有一个example.dmp文件,原来用户为olduser,存储空间为example,example_temp;

我们需要更改用户名及存储表空间导入到新的库中,只需要按照如下步骤进行:

1、建立新的表空间(假设名称:newtablespace)及临时表空间(假设名称:newtablespace_temp),语句如下

–表空间

create tablespace newtablespace
logging  
datafile 'D:\app\Administrator\oradata\newtablespace.dbf' 
size 50m  
autoextend on  
next 50m maxsize 20480m
extent management local;  

–临时表空间

create temporary tablespace newtablespace_temp 
tempfile 'D:\app\Administrator\oradata\newtablespace_temp.dbf' 
size 50m  
autoextend on  
next 50m maxsize 20480m  
extent management local;

–注:具体参数及参数值根据实际情况调整。

2、建立用户(此步骤可省略)

create user newuser identified by admin  
default tablespace newtablespace
temporary tablespace newtablespace_temp;

3、导入

在oracle服务器cmd执行如下命令:

impdp system/admin@DNACLIENT 
directory=DATA_PUMP_DIR 
dumpfile=example.DMP 
REMAP_SCHEMA=olduser:newuser  
remap_tablespace=EXAMPLE:newtablespace,EXAMPLE_TEMP:newtablespace_temp

注:

1、此处directory使用了系统自带的,如果需要自定义,请使用 create directory命令创建;

2、remap_tablespace参数可以写多个表空间隐射,多个表空间转换用逗号隔开。

完成以上步骤,通过plsql利用newuser登录数据库,可以查看到newuser下的所有导入的表已转入newtablespace表空间了。

其他备注:

1、expdp命令:
expdp user/passwd@orcl schemas=user dumpfile=expdp.dmp directory=data_dir logfile=expdp.log;
2 、impdp导入的过程中会自动创建用户,根据以前使用exp/imp的习惯,在imp之前我们通常会建好表空间和用户。在使用impdp的时候,如果先建好了用户,导入的过程中会提示:
“ORA-31684:Object type user: XXX already exists”,所以impdp之前可以不用先建用户,不过出现上面那个提示也不影响。
3、impdp命令在导入数据时,如果用户不存在,则会自动创建该用户,因为expdp导出的dmp文件中包含了创建用户的脚本信息(包括密码,缺省表空间,临时表空间等)。impdp自动创建用户有一个前提条件,就是需要首先创建用户的缺省表空间和临时表空间,如果缺省表空间或者临时表空间不存在,则自动创建用户会失败,导致导入数据的失败。
4、常用查询语句:
#查看用户和默认表空间的关系 select username,default_tablespace,temporary_tablespace from dba_users; #查询所有的表空间 select tablespace_name from dba_tablespaces; #查询某用户下所有表的表名 select count(*) from dba_tables where owner='TEST'; #查询表空间文件所在路径 select * from dba_data_files where tablespace_name = '大写表空间名'; #查询oracle数据泵expdp导出目录 select * from dba_directories;
5、高版本数据导入到低版本中:
如果是使用impdp/empdp来进行导出和导入数据库的话,在高版本的数据库中导出dmp文件时需要在末尾增加要导入的数据库的版本号(低版本oracle),导出语句如下:
expdp \'sys/pwdphxg0898 as sysdba\' DIRECTORY=db_bak DUMPFILE=201701221613.dmp full=y version=11.2.0.1.0

  • 4
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值