日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Oracle简单常用的数据泵导出导入(expdp/impdp)命令举例(下)

發布時間:2023/12/20 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Oracle简单常用的数据泵导出导入(expdp/impdp)命令举例(下) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

轉載自:http://www.cnblogs.com/jyzhao/p/4530575.html

目的:指導項目側自行進行簡單的數據泵遷移工作。

本文實驗環境:Oracle 11.2.0.4,利用數據庫自帶的scott示例用戶進行試驗測試。
根據《簡單常用的數據泵導出導入(expdp/impdp)命令舉例(上)》的expdp導出的二進制文件進行impdp導入。

1.首先需要創建Directory

2.創建表空間和用戶及賦權

3.使用impdp導入用戶數據

3.1 導入scott用戶的元數據,且不包含統計信息;
3.2 導入scott用戶的數據;
3.3 導入scott用戶下的emp,dept表及數據;
3.4 導入scott用戶下的emp,dept表結構;
3.5 導入scott用戶下所有的內容;
3.6 并行導入scott用戶下所有的內容;
4. 特殊需求

4.1 如果導入環境的用戶不同;
4.2 如果導入環境的表空間也不同;

由于我這里的實驗環境還是導出的那臺主機,所以需要先模擬出一個導入的環境,你實際導入并不需要。

1.刪除scott用戶;

drop user scott cascade;

2.刪除users表空間。

drop tablespace users including contents and datafiles;

可能users表空間是默認的數據庫表空間,導致刪除失敗,只需要更改下再執行刪除即可。

select a.property_name, a.property_value from database_properties a where a.property_name like '%DEFAULT%'; alter database default tablespace DBS_D_XXX;

這樣就模擬出了一個沒有users表空間和scott用戶的嶄新環境。

1. 首先需要創建Directory

這里目錄名字定義為”jy”,
若是windows平臺,對應系統目錄為”E:\jingyu”;

create or replace directory jy as 'E:\jingyu';

若是Unix/Linux平臺,對應系統目錄為”/tmp/jingyu”.

create or replace directory jy as '/tmp/jingyu';

注意:目錄在系統上需要真實存在(mkdir -p /tmp/jingyu),且有訪問的權限。
drwxr-xr-x. 2 oracle oinstall 4.0K May 22 16:48 jingyu

2. 創建表空間和用戶及賦權

create tablespace users datafile '+data1' size 10M autoextend on maxsize 30G; create user scott identified by tiger default tablespace users; grant connect, resource to scott; grant read, write on directory jy to scott;

3. 使用impdp導入用戶數據

初始化環境:
初始1:得到刪除當前用戶下表的SQL:select 'drop table '||table_name||' purge;' from user_tables;
初始2:得到查詢當前用戶下表的數據量:select 'select count(1) from '||table_name||';' from user_tables;

3.1 導入scott用戶的元數據,且不包含統計信息;

impdp system directory=jy dumpfile=scott_meta.dmp logfile=impdp_scott_meta.log

$ impdp system directory=jy dumpfile=scott_meta.dmp logfile=impdp_scott_meta.logImport: Release 11.2.0.4.0 - Production on Tue May 26 13:36:41 2015Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Password: Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded Starting "SYSTEM"."SYS_IMPORT_FULL_01": system/******** directory=jy dumpfile=scott_meta.dmp logfile=impdp_scott_meta.log Processing object type SCHEMA_EXPORT/USER ORA-31684: Object type USER:"SCOTT" 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/GRANT/OWNER_GRANT/OBJECT_GRANT Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT Job "SYSTEM"."SYS_IMPORT_FULL_01" completed with 1 error(s) at Tue May 26 13:36:49 2015 elapsed 0 00:00:03

3.2 導入scott用戶的數據;

在3.1導入元數據后才可以導入數據。
impdp system directory=jy dumpfile=scott_data.dmp logfile=impdp_scott_data.log

$ impdp system directory=jy dumpfile=scott_data.dmp logfile=impdp_scott_data.logImport: Release 11.2.0.4.0 - Production on Tue May 26 13:39:15 2015Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Password: Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded Starting "SYSTEM"."SYS_IMPORT_FULL_01": system/******** directory=jy dumpfile=scott_data.dmp logfile=impdp_scott_data.log Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA . . imported "SCOTT"."DEPT" 5.929 KB 4 rows . . imported "SCOTT"."EMP" 8.484 KB 12 rows . . imported "SCOTT"."SALGRADE" 5.859 KB 5 rows . . imported "SCOTT"."BONUS" 0 KB 0 rows Job "SYSTEM"."SYS_IMPORT_FULL_01" successfully completed at Tue May 26 13:39:26 2015 elapsed 0 00:00:07

3.3 只導入scott用戶下的emp表及數據;

這里為了演示導入,先初始化刪除scott用戶下的所有表。

impdp scott directory=jy tables=emp dumpfile=scott_emp_dept.dmp logfile=impdp_scott_emp.log

$ impdp scott directory=jy tables=emp dumpfile=scott_emp_dept.dmp logfile=impdp_scott_emp.logImport: Release 11.2.0.4.0 - Production on Tue May 26 13:50:51 2015Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Password: Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options Master table "SCOTT"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded Starting "SCOTT"."SYS_IMPORT_TABLE_01": scott/******** directory=jy tables=emp dumpfile=scott_emp_dept.dmp logfile=impdp_scott_emp.log Processing object type TABLE_EXPORT/TABLE/TABLE Processing object type TABLE_EXPORT/TABLE/TABLE_DATA . . imported "SCOTT"."EMP" 8.484 KB 12 rows Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS Job "SCOTT"."SYS_IMPORT_TABLE_01" successfully completed at Tue May 26 13:50:59 2015 elapsed 0 00:00:03

3.4 只導入scott用戶下的emp,dept表結構;

這里為了演示導入,先初始化刪除scott用戶下的所有表。

impdp scott directory=jy tables=emp,dept dumpfile=scott_emp_dept_meta.dmp logfile=impdp_scott_emp_dept_meta.log

$ impdp scott directory=jy tables=emp,dept dumpfile=scott_emp_dept_meta.dmp logfile=impdp_scott_emp_dept_meta.logImport: Release 11.2.0.4.0 - Production on Tue May 26 13:54:38 2015Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Password: Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options Master table "SCOTT"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded Starting "SCOTT"."SYS_IMPORT_TABLE_01": scott/******** directory=jy tables=emp,dept dumpfile=scott_emp_dept_meta.dmp logfile=impdp_scott_emp_dept_meta.log Processing object type TABLE_EXPORT/TABLE/TABLE Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS Job "SCOTT"."SYS_IMPORT_TABLE_01" successfully completed at Tue May 26 13:54:45 2015 elapsed 0 00:00:03

由于導出就是emp,dept兩張表,所以也可以不指定tables,以下兩種寫法在這里都是可以的:
impdp scott directory=jy dumpfile=scott_emp_dept_meta.dmp logfile=impdp_scott_emp_dept_meta.log

impdp scott directory=jy dumpfile=scott_emp_dept_meta.dmp logfile=impdp_scott_emp_dept_meta.log full=y

3.5 導入scott用戶下所有的內容;

impdp system directory=jy schemas=scott dumpfile=scott_all.dmp logfile=impdp_scott_all.log

如果是在2.4基礎上直接導入,會因為emp,dept表已經存在導致導入過程中會由于table_exists_action參數的默認選項是skip,從而跳過emp,dept表數據的導入,如下:

$ impdp system directory=jy schemas=scott dumpfile=scott_all.dmp logfile=impdp_scott_all.logImport: Release 11.2.0.4.0 - Production on Tue May 26 14:22:50 2015Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Password: Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options Master table "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01": system/******** directory=jy schemas=scott dumpfile=scott_all.dmp logfile=impdp_scott_all.log Processing object type SCHEMA_EXPORT/USER ORA-31684: Object type USER:"SCOTT" 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 ORA-39151: Table "SCOTT"."DEPT" exists. All dependent metadata and data will be skipped due to table_exists_action of skip ORA-39151: Table "SCOTT"."EMP" exists. All dependent metadata and data will be skipped due to table_exists_action of skip Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA . . imported "SCOTT"."SALGRADE" 5.859 KB 5 rows . . imported "SCOTT"."BONUS" 0 KB 0 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/STATISTICS/TABLE_STATISTICS Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" completed with 3 error(s) at Tue May 26 14:22:57 2015 elapsed 0 00:00:03

所以這時我們想導入這些數據,可以加參數 table_exists_action,指定想要的選項。
TABLE_EXISTS_ACTION
Action to take if imported object already exists.
Valid keywords are: APPEND, REPLACE, [SKIP] and TRUNCATE.

這里選擇truncate,即如果表存在,那么處理方式是truncate此表后導入文件中包含的數據。
impdp system directory=jy schemas=scott table_exists_action=truncate dumpfile=scott_all.dmp logfile=impdp_scott_all.log

$ impdp system directory=jy schemas=scott table_exists_action=truncate dumpfile=scott_all.dmp logfile=impdp_scott_all.logImport: Release 11.2.0.4.0 - Production on Tue May 26 14:26:09 2015Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Password: Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options Master table "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01": system/******** directory=jy schemas=scott table_exists_action=truncate dumpfile=scott_all.dmp logfile=impdp_scott_all.log Processing object type SCHEMA_EXPORT/USER ORA-31684: Object type USER:"SCOTT" 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 Table "SCOTT"."DEPT" exists and has been truncated. Data will be loaded but all dependent metadata will be skipped due to table_exists_action of truncate Table "SCOTT"."BONUS" exists and has been truncated. Data will be loaded but all dependent metadata will be skipped due to table_exists_action of truncate Table "SCOTT"."SALGRADE" exists and has been truncated. Data will be loaded but all dependent metadata will be skipped due to table_exists_action of truncate Table "SCOTT"."EMP" exists and has been truncated. Data will be loaded but all dependent metadata will be skipped due to table_exists_action of truncate Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA . . imported "SCOTT"."DEPT" 5.929 KB 4 rows . . imported "SCOTT"."EMP" 8.484 KB 12 rows . . imported "SCOTT"."SALGRADE" 5.859 KB 5 rows . . imported "SCOTT"."BONUS" 0 KB 0 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/STATISTICS/TABLE_STATISTICS Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" completed with 1 error(s) at Tue May 26 14:26:17 2015 elapsed 0 00:00:04

注意:如果這里選用append選項,那么如果原表有數據,且沒有合理的約束條件,則可能導致數據的重復導入,所以,生產環境實際導入過程中一定要弄清楚數據的實際情況才能準確決定如何選用此參數的選項。
如下所示,SALGRADE表會出現5條重復數據:
impdp system directory=jy schemas=scott table_exists_action=append dumpfile=scott_all.dmp logfile=impdp_scott_all.log

$ impdp system directory=jy schemas=scott table_exists_action=append dumpfile=scott_all.dmp logfile=impdp_scott_all.logImport: Release 11.2.0.4.0 - Production on Tue May 26 14:28:27 2015Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Password: Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options Master table "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01": system/******** directory=jy schemas=scott table_exists_action=append dumpfile=scott_all.dmp logfile=impdp_scott_all.log Processing object type SCHEMA_EXPORT/USER ORA-31684: Object type USER:"SCOTT" 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 Table "SCOTT"."DEPT" exists. Data will be appended to existing table but all dependent metadata will be skipped due to table_exists_action of append Table "SCOTT"."BONUS" exists. Data will be appended to existing table but all dependent metadata will be skipped due to table_exists_action of append Table "SCOTT"."SALGRADE" exists. Data will be appended to existing table but all dependent metadata will be skipped due to table_exists_action of append Table "SCOTT"."EMP" exists. Data will be appended to existing table but all dependent metadata will be skipped due to table_exists_action of append Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA ORA-31693: Table data object "SCOTT"."DEPT" failed to load/unload and is being skipped due to error: ORA-00001: unique constraint (SCOTT.PK_DEPT) violated ORA-31693: Table data object "SCOTT"."EMP" failed to load/unload and is being skipped due to error: ORA-00001: unique constraint (SCOTT.BIN$ESfmGQ7ZSsLgU58JqMBQqw==$0) violated . . imported "SCOTT"."SALGRADE" 5.859 KB 5 rows . . imported "SCOTT"."BONUS" 0 KB 0 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/STATISTICS/TABLE_STATISTICS Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" completed with 3 error(s) at Tue May 26 14:28:34 2015 elapsed 0 00:00:03

3.6 并行導入scott用戶下所有的內容;

impdp system directory=jy schemas=scott table_exists_action=replace dumpfile=scott_all%U.dmp logfile=impdp_scott_all.log parallel=2

這里對于已經存在的對象直接replace掉。

$ impdp system directory=jy schemas=scott table_exists_action=replace dumpfile=scott_all%U.dmp logfile=impdp_scott_all.log parallel=2Import: Release 11.2.0.4.0 - Production on Tue May 26 14:15:37 2015Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Password: Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options Master table "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01": system/******** directory=jy schemas=scott table_exists_action=replace dumpfile=scott_all%U.dmp logfile=impdp_scott_all.log parallel=2 Processing object type SCHEMA_EXPORT/USER ORA-31684: Object type USER:"SCOTT" 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 "SCOTT"."DEPT" 5.929 KB 4 rows . . imported "SCOTT"."EMP" 8.484 KB 12 rows . . imported "SCOTT"."SALGRADE" 5.859 KB 5 rows . . imported "SCOTT"."BONUS" 0 KB 0 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/STATISTICS/TABLE_STATISTICS Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" completed with 1 error(s) at Tue May 26 14:15:46 2015 elapsed 0 00:00:05

4. 特殊需求

特殊需求環境準備:
創建表空間users2:

create tablespace users2 datafile '+data1' size 10M autoextend on maxsize 30G;

創建用戶scott2:

create user scott2 identified by tiger default tablespace users2;

賦權用戶scott2:

grant connect, resource to scott2;

4.1 如果導入環境的用戶不同;

需求:將原scott用戶的數據導入到現在的scott2用戶。
impdp system directory=jy schemas=scott REMAP_SCHEMA=scott:scott2 table_exists_action=replace dumpfile=scott_all%U.dmp logfile=impdp_scott_all.log parallel=2

$ impdp system directory=jy schemas=scott REMAP_SCHEMA=scott:scott2 table_exists_action=replace dumpfile=scott_all%U.dmp logfile=impdp_scott_all.log parallel=2Import: Release 11.2.0.4.0 - Production on Tue May 26 14:55:02 2015Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Password: Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options Master table "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01": system/******** directory=jy schemas=scott REMAP_SCHEMA=scott:scott2 table_exists_action=replace dumpfile=scott_all%U.dmp logfile=impdp_scott_all.log parallel=2 Processing object type SCHEMA_EXPORT/USER ORA-31684: Object type USER:"SCOTT2" 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 "SCOTT2"."DEPT" 5.929 KB 4 rows . . imported "SCOTT2"."EMP" 8.484 KB 12 rows . . imported "SCOTT2"."SALGRADE" 5.859 KB 5 rows . . imported "SCOTT2"."BONUS" 0 KB 0 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/STATISTICS/TABLE_STATISTICS Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" completed with 1 error(s) at Tue May 26 14:55:09 2015 elapsed 0 00:00:04

4.2 如果導入環境的表空間也不同;

需求:將原users表空間的對象重定向到users2表空間。
impdp system directory=jy schemas=scott REMAP_SCHEMA=scott:scott2 REMAP_TABLESPACE=users:users2 table_exists_action=replace dumpfile=scott_all%U.dmp logfile=impdp_scott_all.log parallel=2

$ impdp system directory=jy schemas=scott REMAP_SCHEMA=scott:scott2 REMAP_TABLESPACE=users:users2 table_exists_action=replace dumpfile=scott_all%U.dmp logfile=impdp_scott_all.log parallel=2Import: Release 11.2.0.4.0 - Production on Tue May 26 14:57:20 2015Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Password: Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options Master table "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01": system/******** directory=jy schemas=scott REMAP_SCHEMA=scott:scott2 REMAP_TABLESPACE=users:users2 table_exists_action=replace dumpfile=scott_all%U.dmp logfile=impdp_scott_all.log parallel=2 Processing object type SCHEMA_EXPORT/USER ORA-31684: Object type USER:"SCOTT2" 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 "SCOTT2"."DEPT" 5.929 KB 4 rows . . imported "SCOTT2"."EMP" 8.484 KB 12 rows . . imported "SCOTT2"."SALGRADE" 5.859 KB 5 rows . . imported "SCOTT2"."BONUS" 0 KB 0 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/STATISTICS/TABLE_STATISTICS Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" completed with 1 error(s) at Tue May 26 14:57:29 2015 elapsed 0 00:00:05

細心的朋友,會發現導入的日志最后都提示有一個錯誤,往上查發現是報錯ORA-31684用戶已存在,這是因為我們習慣在導入前建立好對應的用戶,避免一些其他的權限錯誤,所以這個錯誤是可以忽略的。
當然其實如果我們已經建立了對應的表空間,用戶也是可以不事先建立的,比如:
我們這里的情景,如果只事先建立users2表空間,不建立scott2用戶,也是可以成功導入且不會有任何報錯提示。

$ impdp system directory=jy schemas=scott REMAP_SCHEMA=scott:scott2 REMAP_TABLESPACE=users:users2 table_exists_action=replace dumpfile=scott_all%U.dmp logfile=impdp_scott_all.log parallel=2Import: Release 11.2.0.4.0 - Production on Tue May 26 15:03:33 2015Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Password: Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options Master table "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01": system/******** directory=jy schemas=scott REMAP_SCHEMA=scott:scott2 REMAP_TABLESPACE=users:users2 table_exists_action=replace dumpfile=scott_all%U.dmp logfile=impdp_scott_all.log parallel=2 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/TABLE_DATA . . imported "SCOTT2"."DEPT" 5.929 KB 4 rows . . imported "SCOTT2"."EMP" 8.484 KB 12 rows . . imported "SCOTT2"."SALGRADE" 5.859 KB 5 rows . . imported "SCOTT2"."BONUS" 0 KB 0 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/STATISTICS/TABLE_STATISTICS Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully completed at Tue May 26 15:03:42 2015 elapsed 0 00:00:05

總結

以上是生活随笔為你收集整理的Oracle简单常用的数据泵导出导入(expdp/impdp)命令举例(下)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。