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

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

 

Sql代码    收藏代码
  1. sqlplus system/manager  
  2.   
  3. 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.   
  3. expdp cux/cux TABLES=cux_expdp_test_table DUMPFILE=cux_expdp_test_table.dmp DIRECTORY=test_dir LOGFILE=cux_expdp_test_table.log  
  4.   
  5. 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. . . . . . .  
  5.   
  6. $ sqlplus system/manager  
  7. SQL*Plus: Release 11.2.0.2.0 Production on Wed May 15 15:20:58 2013  
  8. Copyright (c) 1982, 2010, Oracle.  All rights reserved.  
  9. Connected to:  
  10. Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production  
  11. With the Partitioning, OLAP, Data Mining and Real Application Testing options  
  12. SQL> create directory test_dir as '/home/orauat/zzj';  
  13. Directory created.  
  14. SQL> Grant read,write on directory test_dir to cux;  
  15. Grant succeeded.  
  16. SQL> exit  
  17. 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  
  18. $ cd /home/orauat/zzj  
  19. $ expdp cux/cux TABLES=cux_expdp_test_table DUMPFILE=cux_expdp_test_table.dmp DIRECTORY=test_dir LOGFILE=cux_expdp_test_table.log  
  20. Export: Release 11.2.0.2.0 - Production on Wed May 15 15:06:12 2013  
  21. Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.  
  22. ;;;   
  23.   
  24. 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  
  25. 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   
  26. Estimate in progress using BLOCKS method...  
  27. Processing object type TABLE_EXPORT/TABLE/TABLE_DATA  
  28. Total estimation using BLOCKS method: 128 KB  
  29. Processing object type TABLE_EXPORT/TABLE/TABLE  
  30. . . exported "CUX"."CUX_EXPDP_TEST_TABLE"                5.460 KB       5 rows  
  31. Master table "CUX"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded  
  32. ******************************************************************************  
  33. Dump file set for CUX.SYS_EXPORT_TABLE_01 is:  
  34.   /export/home/orauat/zzj/cux_expdp_test_table.dmp  
  35. Job "CUX"."SYS_EXPORT_TABLE_01" successfully completed at 15:07:02  
  36. $ ls  
  37. cux_expdp_test_table.dmp      cux_expdp_test_table.log  
  38. $  

 

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. . . .   
  5.   
  6. $ sqlplus system/manager  
  7. SQL*Plus: Release 11.2.0.2.0 Production on Wed May 15 15:20:58 2013  
  8. Copyright (c) 1982, 2010, Oracle.  All rights reserved.  
  9. Connected to:  
  10. Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production  
  11. With the Partitioning, OLAP, Data Mining and Real Application Testing options  
  12. SQL> create directory test_dir as '/home/oracrp2/zzj';  
  13. Directory created.  
  14. SQL> Grant read,write on directory test_dir to cux;  
  15. Grant succeeded.  
  16. SQL> exit  
  17. 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  
  18. $ cd /home/oracrp2/zzj  
  19. $ ls  
  20. cux_expdp_test_table.dmp  
  21. $ impdp cux/cux DIRECTORY=test_dir DUMPFILE=cux_expdp_test_table.dmp TABLE_EXISTS_ACTION=TRUNCATE LOGFILE=cux_expdp_test_table.log  
  22. Import: Release 11.2.0.2.0 - Production on Wed May 15 15:21:55 2013  
  23. Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.  
  24. 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  
  25. Master table "CUX"."SYS_IMPORT_FULL_01" successfully loaded/unloaded  
  26. 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   
  27. Processing object type TABLE_EXPORT/TABLE/TABLE  
  28. Processing object type TABLE_EXPORT/TABLE/TABLE_DATA  
  29. . . imported "CUX"."CUX_EXPDP_TEST_TABLE"                5.460 KB       5 rows  
  30. Job "CUX"."SYS_IMPORT_FULL_01" successfully completed at 15:22:22  
  31. $ ls  
  32. cux_expdp_test_table.dmp      cux_expdp_test_table.log  
  33. $  

猜你喜欢

转载自junyan2579.iteye.com/blog/1870298