1、数据导出基础
(1)创建datapump导出文件的目录对象并为相应用户授予权限。
出于安全考虑,不允许oracle用户直接在OS上进行文件的操作,而应通过directory对象指定。
SQL> create directory dpump_dir1 AS '/opt/oracle/admin/orcl11g/dpdump'; Directory created. SQL> grant read, write on directorydpump_dir1 to scott; Grant succeeded.
(2)导出
[oracle@lujinhong dpdump]$ expdpscott/tiger directory=DPUMP_DIR1 dumpfile=scott.dmp nologfile=y Export: Release 11.2.0.1.0 - Productionon Tue Apr 23 20:24:44 2013 Copyright (c) 1982, 2009, Oracle and/orits affiliates. All rights reserved. Connected to: Oracle Database 11gEnterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Miningand Real Application Testing options Starting"SCOTT"."SYS_EXPORT_SCHEMA_01": scott/******** directory=DPUMP_DIR1dumpfile=scott.dmp nologfile=y Estimate in progress using BLOCKSmethod... Processing object typeSCHEMA_EXPORT/TABLE/TABLE_DATA Total estimation using BLOCKS method:192 KB Processing object typeSCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA Processing object typeSCHEMA_EXPORT/TABLE/TABLE Processing object typeSCHEMA_EXPORT/TABLE/INDEX/INDEX Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT Processing object typeSCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS Processing object typeSCHEMA_EXPORT/TABLE/COMMENT Processing object typeSCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT Processing object typeSCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS . . exported"SCOTT"."DEPT" 5.937 KB 4 rows . . exported"SCOTT"."EMP" 8.570 KB 14 rows . . exported"SCOTT"."SALGRADE" 5.867 KB 5 rows . . exported"SCOTT"."BONUS" 0 KB 0 rows Master table"SCOTT"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded ****************************************************************************** Dump file set forSCOTT.SYS_EXPORT_SCHEMA_01 is: /opt/oracle/admin/orcl11g/dpdump/scott.dmp Job"SCOTT"."SYS_EXPORT_SCHEMA_01" successfully completed at20:25:08
注意:directory=DPUMP_DIR1中的DPUMP_DIR1应该在dba_directories中存在,否则应该在第一步中先创建然后授权。
2、数据导入基础
若即将导入的用户或者表空间不存在,则必须先创建用户及表空间。
[oracle@lujinhong dpdump]$ impdp sys/Lu123456 directory=dpump_dir1dumpfile=scott.dmp Import: Release 11.2.0.1.0 - Productionon Tue Apr 23 20:27:30 2013 Copyright (c) 1982, 2009, Oracle and/orits affiliates. All rights reserved. UDI-28009: operation generated ORACLEerror 28009 ORA-28009: connection as SYS should beas SYSDBA or SYSOPER Username: sys as sysdba Password: Connected to: Oracle Database 11gEnterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Miningand Real Application Testing options Master table"SYS"."SYS_IMPORT_FULL_01" successfully loaded/unloaded Starting"SYS"."SYS_IMPORT_FULL_01": sys/******** AS SYSDBA directory=dpump_dir1 dumpfile=scott.dmp Processing object typeSCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA Processing object typeSCHEMA_EXPORT/TABLE/TABLE ORA-39151: Table"SCOTT"."DEPT" exists. All dependent metadata and data willbe skipped due to table_exists_action of skip ORA-39151: Table "SCOTT"."EMP"exists. All dependent metadata and data will be skipped due totable_exists_action of skip ORA-39151: Table"SCOTT"."BONUS" exists. All dependent metadata and datawill be skipped due to table_e