搜索
首页数据库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
mysql:blob和其他无-SQL存储,有什么区别?mysql:blob和其他无-SQL存储,有什么区别?May 13, 2025 am 12:14 AM

mysql'sblobissuitableForStoringBinaryDataWithInareLationalDatabase,而alenosqloptionslikemongodb,redis和calablesolutionsoluntionsoluntionsoluntionsolundortionsolunsolunsstructureddata.blobobobsimplobissimplobisslowderperformandperformanceperformancewithlararengelitiate;

mySQL添加用户:语法,选项和安全性最佳实践mySQL添加用户:语法,选项和安全性最佳实践May 13, 2025 am 12:12 AM

toaddauserinmysql,使用:createUser'username'@'host'Indessify'password'; there'showtodoitsecurely:1)choosethehostcarecarefullytocon trolaccess.2)setResourcelimitswithoptionslikemax_queries_per_hour.3)usestrong,iniquepasswords.4)Enforcessl/tlsconnectionswith

MySQL:如何避免字符串数据类型常见错误?MySQL:如何避免字符串数据类型常见错误?May 13, 2025 am 12:09 AM

toAvoidCommonMistakeswithStringDatatatPesInMysQl,CloseStringTypenuances,chosethirtightType,andManageEngencodingAndCollat​​ionsEttingsefectery.1)usecharforfixed lengengters lengengtings,varchar forbariaible lengength,varchariable length,andtext/blobforlabforlargerdata.2 seterters seterters seterters seterters

mySQL:字符串数据类型和枚举?mySQL:字符串数据类型和枚举?May 13, 2025 am 12:05 AM

mysqloffersechar,varchar,text,and denumforstringdata.usecharforfixed Lengttrings,varcharerforvariable长度,文本forlarger文本,andenumforenforcingDataAntegrityWithaEtofValues。

mysql blob:如何优化斑点请求mysql blob:如何优化斑点请求May 13, 2025 am 12:03 AM

优化MySQLBLOB请求可以通过以下策略:1.减少BLOB查询频率,使用独立请求或延迟加载;2.选择合适的BLOB类型(如TINYBLOB);3.将BLOB数据分离到单独表中;4.在应用层压缩BLOB数据;5.对BLOB元数据建立索引。这些方法结合实际应用中的监控、缓存和数据分片,可以有效提升性能。

将用户添加到MySQL:完整的教程将用户添加到MySQL:完整的教程May 12, 2025 am 12:14 AM

掌握添加MySQL用户的方法对于数据库管理员和开发者至关重要,因为它确保数据库的安全性和访问控制。1)使用CREATEUSER命令创建新用户,2)通过GRANT命令分配权限,3)使用FLUSHPRIVILEGES确保权限生效,4)定期审计和清理用户账户以维护性能和安全。

掌握mySQL字符串数据类型:varchar vs.文本与char掌握mySQL字符串数据类型:varchar vs.文本与charMay 12, 2025 am 12:12 AM

chosecharforfixed-lengthdata,varcharforvariable-lengthdata,andtextforlargetextfield.1)chariseffity forconsistent-lengthdatalikecodes.2)varcharsuitsvariable-lengthdatalikenames,ballancingflexibilitibility andperformance.3)

MySQL:字符串数据类型和索引:最佳实践MySQL:字符串数据类型和索引:最佳实践May 12, 2025 am 12:11 AM

在MySQL中处理字符串数据类型和索引的最佳实践包括:1)选择合适的字符串类型,如CHAR用于固定长度,VARCHAR用于可变长度,TEXT用于大文本;2)谨慎索引,避免过度索引,针对常用查询创建索引;3)使用前缀索引和全文索引优化长字符串搜索;4)定期监控和优化索引,保持索引小巧高效。通过这些方法,可以在读取和写入性能之间取得平衡,提升数据库效率。

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脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器