搜尋
首頁資料庫mysql教程Oracle 10g的EXPDP与IMPDP的导出与导入测试

通过DB_LINK的复制功能,利用expdp,impdp进行数据的远程备份及恢复。进行测试前,将服务器B上scott用户的dept,emp进行删除,本测

实验环境:

服务器A:172.21.1.30

服务器B:172.21.1.40

两台服务器上分别运行两套Oracle数据库,本实验以scott用户为例进行测试。

实验目的:

通过DB_LINK的复制功能,利用expdp,impdp进行数据的远程备份及恢复。进行测试前,将服务器B上scott用户的dept,emp进行删除,本测试只是使用impdp将服务器A数据库下scott用户的dept,emp表导入到服务器B数据库scott用户下。

操作步骤:

1.在服务器A,B上分别以sys身份登录数据库,并创建directory,db_link,命令如下:

session A: > create directory dp01 as '/bk/dp01';

Directory created.

session A: >create public database link ln_db40 connect to scott identified by tiger using 'ip40';

Database link created.

session A: >grant  connect,resource,exp_full_database,imp_full_database  to scott identified by tiger;

Grant succeeded.

 

session B: > create directory dp02 as '/bk/dp02';

Directory created.

session B: >create public database link ln_db30 connect to scott identified by tiger using 'ip30';

Database link created.

session B: >grant  connect,resource,exp_full_database,imp_full_database  to scott identified by tiger;

Grant succeeded.

 

2.在确认以上步骤中的db_link没问题后,做以下操作:

 

a.    服务器A:(将本地数据库中scott用户下的dept,emp两张表导出备份文件为exp01.dmp)

[oracle@session A: dp01]$  expdp scott/tiger directory=dp01 dumpfile=exp01.dmp  network_link=ln_db30  tables=emp,dept

 

Export: Release 10.2.0.1.0 - Production on Wednesday, 03 August, 2011 14:39:05

Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Starting "SCOTT"."SYS_EXPORT_SCHEMA_01":  scott/********@ip30 directory=dp01 dumpfile=exp01.dmp network_link=ln_db30  tables=emp,dept
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 320 KB
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/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/COMMENT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
. . exported "SCOTT"."SYS_EXPORT_SCHEMA_01"              172.8 KB    1073 rows
. . exported "SCOTT"."DEPT"                              5.656 KB       4 rows
. . exported "SCOTT"."EMP"                               7.820 KB      14 rows
Master table "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_EXPORT_SCHEMA_01 is:
  /bk/dp01/exp01.dmp
Job "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully completed at 14:39:37

 

[oracle@session A: dp01]$ ls

exp01.dmp   export.log  import.log

b. 将备份文件exp01.dmp从服务器A拷贝到服务器B:

[oracle@session A: dp01]$  scp   –r  exp01.dmp   172.21.1.40:/bk/dp02/

 

c.在服务器A上,执行以下命令,将dept,emp表导入到服务器B的scott用户下:


[oracle@session A: dp01]$  impdp scott/tiger@ip40 directory=dp02 dumpfile=exp01.dmp  tables=emp,dept

Import: Release 10.2.0.1.0 - Production on Wednesday, 03 August, 2011 14:34:57

Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Master table "SCOTT"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "SCOTT"."SYS_IMPORT_TABLE_01":  scott/********@ip40 directory=dp02 dumpfile=exp01.dmp tables=emp,dept
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "SCOTT"."DEPT"                              5.656 KB       4 rows
. . imported "SCOTT"."EMP"                               7.820 KB      14 rows
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Job "SCOTT"."SYS_IMPORT_TABLE_01" successfully completed at 14:34:55

3.使用sys用户登录服务器A的数据库,进行测试,查看B的scott用户下的dept,emp表是否存在:

$ sqlplus / as sysdba           

session A: > conn scott/tiger

Connected.

session A: > select * from tab;

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
DEPT                           TABLE
EMP                            TABLE

 

session A: > select * from tab@ln_db40;

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
DEPT                           TABLE
EMP                            TABLE

由以上实验不难看出,表dept,emp已成功导入B的scott用户。

 

 

EXPDP 可以导出所有数据库的数据,只要它能连接到这个数据库,或者它登录的数据库
上能读取到被导出的库的数据,因为此时可以通过数据库链来读取被导出的库的数据。

如下测试:

可以分为三个服务器:A,B,,C,以下命令在A在执行:

[oracle@session A: dp01]$  expdp scott/tiger@ip40 directory=dp02 dumpfile=exp01.dmp  network_link=ln_db50  tables=emp,dept

 

Export: Release 10.2.0.1.0 - Production on Wednesday, 03 August, 2011 14:39:05

Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Starting "SCOTT"."SYS_EXPORT_SCHEMA_01":  scott/********@ip40 directory=dp02 dumpfile=exp01.dmp network_link=ln_db50  tables=emp,dept
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 320 KB
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/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/COMMENT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
. . exported "SCOTT"."SYS_EXPORT_SCHEMA_01"              172.8 KB    1073 rows
. . exported "SCOTT"."DEPT"                              5.656 KB       4 rows
. . exported "SCOTT"."EMP"                               7.820 KB      14 rows
Master table "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_EXPORT_SCHEMA_01 is:
  /bk/dp01/exp01.dmp
Job "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully completed at 14:39:37

 

说明:

expdp 在服务器A上;

scott/tiger@ip40 连接到服务器B的数据库;

network_link=ln_db30 是服务器B的数据库中scott用户的数据库链,其指向服务器C的用户scott,
SCOTT10用户中只有两个表dept,emp.

从上面的操作可以看出:expdp 可以是客户端的程序,但它导出的数据(DMP)必须存放在它登录

的数据库的目录下(本例中,存放在机器B的数据库directory=dp02下),而被导出的数据是通过

数据库链(network_link)到机器C的数据库里读取的。

另外注意:在这过程中,A数据库用户scott和C数据库用户scott(或者数据库链中的用户)都必须被

授予EXP_FULL_DATABASE 权限。

 

nelwork_link意思是从本地数据库导入datafile直接到remote database,中间省略了exp的操作,

nelwork_link=source_database_link,确认nelwork_link参数是一个存在的目标数据库名称,同时

存在database link.

 

补充一下两个限制条件:

nelwork_link parameter Restrictions


Network imports do not support the use of evolved types.

a:  When the NETWORK_LINK parameter is used in conjunction with the TABLES parameter,

only whole tables can be imported (not partitions of tables).

所以,当使用impdp导入时多张表时,如果添加network_link参数,就会报错如下:

UDI-00011: parameter dumpfile is incompatible with parameter network_link


b:  If the USERID that is executing the import job has the IMP_FULL_DATABASE role on the

target database, then that user must also have the EXP_FULL_DATABASE role on the source

database.The only types of database links supported by Data Pump Import are: public,

fixed-user, and connected-user. Current-user database links are not supported.

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
如何使用Alter Table語句在MySQL中更改表?如何使用Alter Table語句在MySQL中更改表?Mar 19, 2025 pm 03:51 PM

本文討論了使用MySQL的Alter Table語句修改表,包括添加/刪除列,重命名表/列以及更改列數據類型。

如何為MySQL連接配置SSL/TLS加密?如何為MySQL連接配置SSL/TLS加密?Mar 18, 2025 pm 12:01 PM

文章討論了為MySQL配置SSL/TLS加密,包括證書生成和驗證。主要問題是使用自簽名證書的安全含義。[角色計數:159]

您如何處理MySQL中的大型數據集?您如何處理MySQL中的大型數據集?Mar 21, 2025 pm 12:15 PM

文章討論了處理MySQL中大型數據集的策略,包括分區,碎片,索引和查詢優化。

哪些流行的MySQL GUI工具(例如MySQL Workbench,PhpMyAdmin)是什麼?哪些流行的MySQL GUI工具(例如MySQL Workbench,PhpMyAdmin)是什麼?Mar 21, 2025 pm 06:28 PM

文章討論了流行的MySQL GUI工具,例如MySQL Workbench和PhpMyAdmin,比較了它們對初學者和高級用戶的功能和適合性。[159個字符]

如何使用Drop Table語句將表放入MySQL中?如何使用Drop Table語句將表放入MySQL中?Mar 19, 2025 pm 03:52 PM

本文討論了使用Drop Table語句在MySQL中放下表,並強調了預防措施和風險。它強調,沒有備份,該動作是不可逆轉的,詳細介紹了恢復方法和潛在的生產環境危害。

您如何用外國鑰匙代表關係?您如何用外國鑰匙代表關係?Mar 19, 2025 pm 03:48 PM

文章討論了使用外國密鑰來代表數據庫中的關係,重點是最佳實踐,數據完整性和避免的常見陷阱。

如何在JSON列上創建索引?如何在JSON列上創建索引?Mar 21, 2025 pm 12:13 PM

本文討論了在PostgreSQL,MySQL和MongoDB等各個數據庫中的JSON列上創建索引,以增強查詢性能。它解釋了索引特定的JSON路徑的語法和好處,並列出了支持的數據庫系統。

如何保護MySQL免受常見漏洞(SQL注入,蠻力攻擊)?如何保護MySQL免受常見漏洞(SQL注入,蠻力攻擊)?Mar 18, 2025 pm 12:00 PM

文章討論了使用準備好的語句,輸入驗證和強密碼策略確保針對SQL注入和蠻力攻擊的MySQL。(159個字符)

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器