---
title: "用expdp/impdp实现将数据从一个数据库导入另一个数据库"
author: "junyan2579"
date: "2013-05-16T13:19:18Z"
tags: []
categories: ["数据库"]
slug: "expdp-impdp"
draft: false
lastmod: "2013-05-16T13:19:18Z"
id: 1870298
url: "https://junyan2579.iteye.com/blog/1870298"
---

1、创建DIRECTORY (必须在数据库用户下创建目录)

 

Sql代码     [![收藏代码](http://zhangzhongjie.iteye.com/images/icon_star.png)](/admin/blogs/ "收藏这段代码")

1. sqlplus system/manager
2. create directory test\_dir as '/home/orauat/zzj';

 

2、授权

 

Sql代码     [![收藏代码](http://zhangzhongjie.iteye.com/images/icon_star.png)](/admin/blogs/ "收藏这段代码")

1. Grant read,write on directory test\_dir to cux;

 

--查看目录及权限

Sql代码     [![收藏代码](http://zhangzhongjie.iteye.com/images/icon_star.png)](/admin/blogs/ "收藏这段代码")

1. SELECT PRIVILEGE, DIRECTORY\_NAME, DIRECTORY\_PATH
2. FROM USER\_TAB\_PRIVS T, ALL\_DIRECTORIES D
3. WHERE T.TABLE\_NAME(+) = D.DIRECTORY\_NAME
4. ORDER BY 2, 1;

 

3、执行导出导入

 

Sql代码     [![收藏代码](http://zhangzhongjie.iteye.com/images/icon_star.png)](/admin/blogs/ "收藏这段代码")

1. su - orauat/orauat
2. expdp cux/cux TABLES=cux\_expdp\_test\_table DUMPFILE=cux\_expdp\_test\_table.dmp DIRECTORY=test\_dir LOGFILE=cux\_expdp\_test\_table.log
3. impdp cux/cux DIRECTORY=test\_dir DUMPFILE=cux\_expdp\_test\_table.dmp TABLE\_EXISTS\_ACTION=TRUNCATE LOGFILE=cux\_expdp\_test\_table.log

 

例子：将UAT环境中表cux.cux\_expdp\_test\_table中的数据导入到CRP2环境中；

 

一、从UAT环境中将数据导出：

 

1、创建DIRECTORY(必须在数据库用户下创建目录)

Sql代码     [![收藏代码](http://zhangzhongjie.iteye.com/images/icon_star.png)](/admin/blogs/ "收藏这段代码")

01. login: orauat
02. orauat's Password:
03. . . . . . .
04. $ sqlplus system/manager
05. SQL\*Plus: Release 11.2.0.2.0 Production on Wed May 15 15:20:58 2013
06. Copyright (c) 1982, 2010, Oracle.  All rights reserved.
07. Connected to:
08. Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
09. With the Partitioning, OLAP, Data Mining and Real Application Testing options
10. SQL&gt; create directory test\_dir as '/home/orauat/zzj';
11. Directory created.
12. SQL&gt; Grant read,write on directory test\_dir to cux;
13. Grant succeeded.
14. SQL&gt; exit
15. Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options
16. $ cd /home/orauat/zzj
17. $ expdp cux/cux TABLES=cux\_expdp\_test\_table DUMPFILE=cux\_expdp\_test\_table.dmp DIRECTORY=test\_dir LOGFILE=cux\_expdp\_test\_table.log
18. Export: Release 11.2.0.2.0 - Production on Wed May 15 15:06:12 2013
19. Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
20. ;;;
21. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options
22. Starting "CUX"."SYS\_EXPORT\_TABLE\_01":  cux/\*\*\*\*\*\*\** TABLES=cux\_expdp\_test\_table DUMPFILE=cux\_expdp\_test\_table.dmp DIRECTORY=test\_dir LOGFILE=cux\_expdp\_test\_table.log
23. Estimate in progress using BLOCKS method...
24. Processing object type TABLE\_EXPORT/TABLE/TABLE\_DATA
25. Total estimation using BLOCKS method: 128 KB
26. Processing object type TABLE\_EXPORT/TABLE/TABLE
27. . . exported "CUX"."CUX\_EXPDP\_TEST\_TABLE"                5.460 KB       5 rows
28. Master table "CUX"."SYS\_EXPORT\_TABLE\_01" successfully loaded/unloaded
29. \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**
30. Dump file set for CUX.SYS\_EXPORT\_TABLE\_01 is:
31. /export/home/orauat/zzj/cux\_expdp\_test\_table.dmp
32. Job "CUX"."SYS\_EXPORT\_TABLE\_01" successfully completed at 15:07:02
33. $ ls
34. cux\_expdp\_test\_table.dmp      cux\_expdp\_test\_table.log
35. $

 

2、将cux\_expdp\_test\_table.dmp从/home/orauat/zzj目录下载下来，然后上传到CRP2环境的/home/oracrp2/zzj

 

二、将数据上传到CRP2环境：

 

1、创建DIRECTORY(必须在数据库用户下创建目录)

Sql代码     [![收藏代码](http://zhangzhongjie.iteye.com/images/icon_star.png)](/admin/blogs/ "收藏这段代码")

01. login: oracrp2
02. oracrp2's Password:
03. . . .
04. $ sqlplus system/manager
05. SQL\*Plus: Release 11.2.0.2.0 Production on Wed May 15 15:20:58 2013
06. Copyright (c) 1982, 2010, Oracle.  All rights reserved.
07. Connected to:
08. Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
09. With the Partitioning, OLAP, Data Mining and Real Application Testing options
10. SQL&gt; create directory test\_dir as '/home/oracrp2/zzj';
11. Directory created.
12. SQL&gt; Grant read,write on directory test\_dir to cux;
13. Grant succeeded.
14. SQL&gt; exit
15. Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options
16. $ cd /home/oracrp2/zzj
17. $ ls
18. cux\_expdp\_test\_table.dmp
19. $ impdp cux/cux DIRECTORY=test\_dir DUMPFILE=cux\_expdp\_test\_table.dmp TABLE\_EXISTS\_ACTION=TRUNCATE LOGFILE=cux\_expdp\_test\_table.log
20. Import: Release 11.2.0.2.0 - Production on Wed May 15 15:21:55 2013
21. Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
22. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options
23. Master table "CUX"."SYS\_IMPORT\_FULL\_01" successfully loaded/unloaded
24. Starting "CUX"."SYS\_IMPORT\_FULL\_01":  cux/\*\*\*\*\*\*\** DIRECTORY=test\_dir DUMPFILE=cux\_expdp\_test\_table.dmp TABLE\_EXISTS\_ACTION=TRUNCATE LOGFILE=cux\_expdp\_test\_table.log
25. Processing object type TABLE\_EXPORT/TABLE/TABLE
26. Processing object type TABLE\_EXPORT/TABLE/TABLE\_DATA
27. . . imported "CUX"."CUX\_EXPDP\_TEST\_TABLE"                5.460 KB       5 rows
28. Job "CUX"."SYS\_IMPORT\_FULL\_01" successfully completed at 15:22:22
29. $ ls
30. cux\_expdp\_test\_table.dmp      cux\_expdp\_test\_table.log
31. $