ORACLE expdp导出远程库指定用户数据到本地数据库

本文涉及的产品
云原生数据仓库AnalyticDB MySQL版,8核32GB 100GB 1个月
简介:     众所周知,ORACLE导出远程库时,我们可以使用exp,但是exp的效率不高,相比之下expdp可以开并行,速度更可控, 下面就说下使用dblink结合expdp导出远程库指定用户到本地数据库的方法。
    众所周知,ORACLE导出远程库时,我们可以使用exp,但是exp的效率不高,相比之下expdp可以开并行,速度更可控,
下面就说下使用dblink结合expdp导出远程库指定用户到本地数据库的方法。
    首先,在本地库创建发起expdp及dblink的用户,并赋予合适的权限
[oracle@linux ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Tue Jul 19 09:29:38 2016
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create user zhul identified by zhul;
User created.
SQL> grant dba to zhul;
Grant succeeded.
    其次,本地创建dblink
SQL> create public database link orcl10g31
 connect to zhul identified by zhul
 using '(DESCRIPTION =
 (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.99.31)(PORT = 1521))
   )
  (CONNECT_DATA =
    (SERVICE_NAME = orcl10g)
  )
 ) ';
Database link created.
    再次,本地创建expdp客户端使用的directory路径
SQL> create directory zhul as '/home/oracle/';
Directory created.
    测试dblink对远程库的访问可用性
SQL> select count(*) from scott.emp@orcl10g31;
  COUNT(*)
----------
14
SQL>
    使用expdp及创建好的dblink导出远程库的指定用户 
[oracle@linux ~]$ expdp zhul/zhul directory=zhul dumpfile=shijiazhuang20160819.dmp logfile=shijiazhuang20160719_exp.log schemas=shijiazhuang network_link=orcl10g31
Export: Release 11.2.0.4.0 - Production on Tue Jul 19 09:35:24 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "ZHUL"."SYS_EXPORT_SCHEMA_01":  zhul/******** directory=zhul dumpfile=shijiazhuang20160819.dmp logfile=shijiazhuang20160719_exp.log schemas=shijiazhuang network_link=orcl10g31 
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 8 MB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "SHIJIAZHUANG"."MR_RESULT"                  162.1 KB    1132 rows
. . exported "SHIJIAZHUANG"."MR_POINTS_DEDUCTION"        30.12 KB     349 rows
. . exported "SHIJIAZHUANG"."MR_CONFIG"                  9.445 KB       5 rows
. . exported "SHIJIAZHUANG"."MR_CONFIG_LOG"              6.117 KB       5 rows
. . exported "SHIJIAZHUANG"."MR_REGION"                  5.468 KB      13 rows
Master table "ZHUL"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for ZHUL.SYS_EXPORT_SCHEMA_01 is:
  /home/oracle/shijiazhuang20160819.dmp
Job "ZHUL"."SYS_EXPORT_SCHEMA_01" successfully completed at Tue Jul 19 09:35:55 2016 elapsed 0 00:00:30
    在本地创建好接收远程库指定用户数据的本地用户,然后使用impdp导入远程库指定用户的数据到本地指定用户下
SQL> create user shijiazhuang identified by shijiazhuang default tablespace shijiazhuang;
User created.
SQL> grant resource to shijiazhuang;
Grant succeeded.
SQL> grant create session to shijiazhuang;
Grant succeeded.
[oracle@linux ~]$ impdp zhul/zhul directory=zhul dumpfile=shijiazhuang20160819.dmp logfile=shijiazhuang20160719_imp.log schemas=shijiazhuang
Import: Release 11.2.0.4.0 - Production on Tue Jul 19 09:36:50 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "ZHUL"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded
Starting "ZHUL"."SYS_IMPORT_SCHEMA_01":  zhul/******** directory=zhul dumpfile=shijiazhuang20160819.dmp logfile=shijiazhuang20160719_imp.log schemas=shijiazhuang 
Processing object type SCHEMA_EXPORT/USER
ORA-31684: Object type USER:"SHIJIAZHUANG" already exists
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "SHIJIAZHUANG"."MR_RESULT"                  162.1 KB    1132 rows
. . imported "SHIJIAZHUANG"."MR_POINTS_DEDUCTION"        30.12 KB     349 rows
. . imported "SHIJIAZHUANG"."MR_CONFIG"                  9.445 KB       5 rows
. . imported "SHIJIAZHUANG"."MR_CONFIG_LOG"              6.117 KB       5 rows
. . imported "SHIJIAZHUANG"."MR_REGION"                  5.468 KB      13 rows
Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "ZHUL"."SYS_IMPORT_SCHEMA_01" completed with 1 error(s) at Tue Jul 19 09:37:06 2016 elapsed 0 00:00:15
    使用过程中可能遇到的问题:
    创建dblink时尽量不要使用tnsname解析,要使用tnsname里的服务全称,否则导出时会遇到如下报错:
C:\Users\localadmin>expdp zhul/zhul directory=myexpdp dumpfile=shijiazhuang20160
819.dmp logfile=shijiazhuang20160719.log schemas=shijiazhuang network_link=orcl1
0g31
Export: Release 11.2.0.1.0 - Production on 星期二 7月 19 09:15:04 2016
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Produc
tion
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORA-39001: 参数值无效
ORA-39200: 链接名称 "orcl10g31" 无效。
ORA-02019: 未找到远程数据库的连接说明
    不要在异构平台下使用expdp,例如:windows导出远程linux/unix下oracle的用户数据,然后通过ftp上传到linux/unix,再使用impdp导入,否则本地导入会遇到如下报错而失败:
[oracle@linux ~]$ impdp shijiazhuang/shijiazhuang DIRECTORY=zhul dumpfile=shijiazhuang20160719.dmp logfile=shijiazhuang20160719_imp.log
Import: Release 11.2.0.4.0 - Production on Tue Jul 19 09:28:52 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORA-39001: invalid argument value
ORA-39000: bad dump file specification
ORA-39143: dump file "/home/oracle/shijiazhuang20160719.dmp" may be an original export dump file
[oracle@linux ~]$ 


相关实践学习
数据库实验室挑战任务-初级任务
本场景介绍如何开通属于你的免费云数据库,在RDS-MySQL中完成对学生成绩的详情查询,执行指定类型SQL。
阿里云云原生数据仓库AnalyticDB MySQL版 使用教程
云原生数据仓库AnalyticDB MySQL版是一种支持高并发低延时查询的新一代云原生数据仓库,高度兼容MySQL协议以及SQL:92、SQL:99、SQL:2003标准,可以对海量数据进行即时的多维分析透视和业务探索,快速构建企业云上数据仓库。 了解产品 https://www.aliyun.com/product/ApsaraDB/ads
目录
相关文章
|
1天前
|
存储 监控 Oracle
关系型数据库Oracle备份策略建议
【7月更文挑战第21天】
10 6
|
1天前
|
存储 Oracle 关系型数据库
|
2天前
|
监控 Oracle 关系型数据库
关系型数据库Oracle恢复测试
【7月更文挑战第20天】
17 7
|
1天前
|
运维 Oracle 关系型数据库
关系型数据库Oracle自动化备份
【7月更文挑战第21天】
10 3
|
2天前
|
存储 Oracle 安全
关系型数据库Oracle备份频率
【7月更文挑战第20天】
10 2
|
18天前
|
SQL 机器学习/深度学习 Oracle
关系型数据库Oracle关键特性
【7月更文挑战第5天】
25 3
|
3天前
|
SQL Oracle 关系型数据库
Oracle 12c有哪些新特性?
【7月更文挑战第20天】Oracle 12c有哪些新特性?
10 2
|
16天前
|
存储 Oracle 关系型数据库
Oracle数据库ACID特性
【7月更文挑战第6天】
28 6
|
SQL 存储 Oracle
在Oracle 12c中,在RMAN方面有哪些增强的新特性?
在Oracle 12c中,在RMAN方面有哪些增强的新特性?
155 0
|
Oracle 关系型数据库 分布式数据库
4.17.2PolarDB兼容Oracle的特性对比
PolarDB兼容Oracle的特性对比 1.PolarDB O提供了以下视图兼容Oracle,哪个除外 A. DBA_TABLES B. DBA_INDEXES C. DBA_DB_FILES D. USER_TABLES 正确答案: C
423 0

推荐镜像

更多