ITeye博客

用expdp/impdp实现将数据从一个数据库导入另一个数据库

junyan2579 · 2013-05-16 13:19 · 2013年5月 · 数据库 · Markdown

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

 

Sql代码   收藏代码

  1. sqlplus system/manager
  2. create directory test_dir as '/home/orauat/zzj';

 

2、授权

 

Sql代码   收藏代码

  1. Grant read,write on directory test_dir to cux;

 

--查看目录及权限

Sql代码   收藏代码

  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代码   收藏代码

  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代码   收藏代码

  1. login: orauat
  2. orauat's Password:
  3. . . . . . .
  4. $ sqlplus system/manager
  5. SQL*Plus: Release 11.2.0.2.0 Production on Wed May 15 15:20:58 2013
  6. Copyright (c) 1982, 2010, Oracle.  All rights reserved.
  7. Connected to:
  8. Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
  9. With the Partitioning, OLAP, Data Mining and Real Application Testing options
  10. SQL> create directory test_dir as '/home/orauat/zzj';
  11. Directory created.
  12. SQL> Grant read,write on directory test_dir to cux;
  13. Grant succeeded.
  14. SQL> 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代码   收藏代码

  1. login: oracrp2
  2. oracrp2's Password:
  3. . . .
  4. $ sqlplus system/manager
  5. SQL*Plus: Release 11.2.0.2.0 Production on Wed May 15 15:20:58 2013
  6. Copyright (c) 1982, 2010, Oracle.  All rights reserved.
  7. Connected to:
  8. Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
  9. With the Partitioning, OLAP, Data Mining and Real Application Testing options
  10. SQL> create directory test_dir as '/home/oracrp2/zzj';
  11. Directory created.
  12. SQL> Grant read,write on directory test_dir to cux;
  13. Grant succeeded.
  14. SQL> 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. $

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。