千家信息网

Oracle 12c pdb使用expdp/impdp导入导出

发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,12c推出了可插拔数据库,在一个容器cdb中以多租户的形式同时存在多个数据库pdb。在为pdb做数据泵导入导出时和传统的数据库有少许不同。1,需要为pdb添加tansnames2,导入导出时需要在us
千家信息网最后更新 2026年11月02日Oracle 12c pdb使用expdp/impdp导入导出

12c推出了可插拔数据库,在一个容器cdb中以多租户的形式同时存在多个数据库pdb。在为pdb做数据泵导入导出时和传统的数据库有少许不同。

1,需要为pdb添加tansnames

2,导入导出时需要在userid参数内指定其tansnames的值,比如 userid=user/pwd@tnsname

数据泵导出

1、查看当前的SID,查看pdb并切换到容器数据库,这里的pluggable数据库是pdborcl
[oracle@test admin]$ echo $ORACLE_SID[oracle@test admin]orcl

登录cdb,查看pdb,

SQL> show con_nameCON_NAME------------------------------CDB$ROOTSQL> show pdbs    CON_ID CON_NAME              OPEN MODE  RESTRICTED---------- ------------------------------ ---------- ----------PDB$SEED                      READ ONLY    NOPDBORCL                       MOUNTEDSQL> alter pluggable database all open;Pluggable database altered.SQL> show pdbs    CON_ID CON_NAME              OPEN MODE  RESTRICTED---------- ------------------------------ ---------- ----------PDB$SEED                      READ ONLY  NOPDBORCL                       READ WRITE NO

切换到pdborcl

SQL> alter session set container=pdborcl;Session altered.SQL>

2、查看示例用户scott,以后的schema级别导入导出就使用该用户的数据。
SQL> select owner, table_name from dba_tables where owner='SCOTT';OWNER                   TABLE_NAME------------------------------ ----------------------------------------SCOTT                   SALGRADESCOTT                   BONUSSCOTT                   EMPSCOTT                   DEPT

3、单独创建一个dba权限的数据泵用户
SQL> grant dba to dp identified by dp;Grant succeeded.

4、创建一个数据泵目录dp_dir,路径为oracle家目录
SQL> create or replace directory dp_dir as  '/home/oracle';Directory created.SQL> exit

5、授予dp用户在数据泵路径有读写权限

(如果是dba权限的这一步可以省略,为了试验的完整性这里保留)

SQL> grant read,write on directory dp_dir to dp;Grant succeeded.

6、设置tnsnames.ora,增加pdborocl。SERVICE_NAME为pdb的实例名,这里为pdborcl
[oracle@xqzt admin]$ pwd/data/app/oracle/product/12.1.0/dbhome_1/network/admin[oracle@xqzt admin]$ cat tnsnames.ora # tnsnames.ora Network Configuration File: /data/app/oracle/product/12.1.0/dbhome_1/network/admin/tnsnames.ora# Generated by Oracle configuration tools.ORCL =  (DESCRIPTION =    (ADDRESS = (PROTOCOL = TCP)(HOST = xqzt)(PORT = 1521))    (CONNECT_DATA =      (SERVER = DEDICATED)      (SERVICE_NAME = orcl)    )  )PDBORCL =  (DESCRIPTION =    (ADDRESS = (PROTOCOL = TCP)(HOST = xqzt)(PORT = 1521))    (CONNECT_DATA =      (SERVER = DEDICATED)      (SERVICE_NAME =pdborcl)    )  )


7、测试tnsnames.ora的有效性,如果返回OK (0 msec)表示配置成功
[oracle@xqzt admin]$ tnsping pdborclTNS Ping Utility for Linux: Version 12.1.0.2.0 - Production on 10-DEC-2015 09:10:34Copyright (c) 1997, 2014, Oracle.  All rights reserved.Used parameter files:/data/app/oracle/product/12.1.0/dbhome_1/network/admin/sqlnet.oraUsed TNSNAMES adapter to resolve the aliasAttempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = xqzt)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME =pdborcl)))OK (0 msec)


8、数据泵导出
    • 用户名密码为dp/dp,并且通过tnsnames指向pdborcl

    • 数据泵目录为:dp_dir, OS路径是/home/oracle

    • 导出文件为:/home/oracle/scott_pdborcl.dmp

    • 导出日志为:/home/oracle/scott_pdborcl.log

    • 导出模式为scheme,也可以理解为用户:scott

[oracle@xqzt ~]$ expdp dp/dp@pdborcl directory=dp_dir dumpfile=scott_pdborcl.dmp logfile=scott_pdborcl.log schemas=scottExport: Release 12.1.0.2.0 - Production on Thu Dec 10 09:32:05 2015Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit ProductionWith the Partitioning, OLAP, Advanced Analytics and Real Application Testing optionsStarting "DP"."SYS_EXPORT_SCHEMA_01":  dp/********@pdborcl directory=dp_dir dumpfile=scott_pdborcl.dmp logfile=scott_pdborcl.log schemas=scott Estimate in progress using BLOCKS method...Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATATotal estimation using BLOCKS method: 192 KBProcessing object type SCHEMA_EXPORT/USERProcessing object type SCHEMA_EXPORT/SYSTEM_GRANTProcessing object type SCHEMA_EXPORT/ROLE_GRANTProcessing object type SCHEMA_EXPORT/DEFAULT_ROLEProcessing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMAProcessing object type SCHEMA_EXPORT/TABLE/TABLEProcessing object type SCHEMA_EXPORT/TABLE/INDEX/INDEXProcessing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINTProcessing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICSProcessing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINTProcessing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICSProcessing object type SCHEMA_EXPORT/STATISTICS/MARKER. . exported "SCOTT"."DEPT"                              6.023 KB       4 rows. . exported "SCOTT"."EMP"                               8.773 KB      14 rows. . exported "SCOTT"."SALGRADE"                          6.023 KB      10 rows. . exported "SCOTT"."BONUS"                                 0 KB       0 rowsMaster table "DP"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded******************************************************************************Dump file set for DP.SYS_EXPORT_SCHEMA_01 is:  /home/oracle/scott_pdborcl.dmpJob "DP"."SYS_EXPORT_SCHEMA_01" successfully completed at Thu Dec 10 09:32:29 2015 elapsed 0 00:00:21[oracle@xqzt ~]$

10、查看导出文件
[oracle@xqzt ~]$ ls  -l scott_pdborcl.dmp  scott_pdborcl.log-rw-r----- 1 oracle oinstall 356352 12月 10 09:32 scott_pdborcl.dmp-rw-r--r-- 1 oracle oinstall   1960 12月 10 09:32 scott_pdborcl.log

11、为了测试导出文件是否能够正常导入,我们先删除pdborcl的scott用户
SQL> select count(*) from scott.DEPT;  COUNT(*)----------SQL> drop user scott cascade  ;User dropped.SQL>

此时访问该用户的表已经不存在了

SQL> select count(*) from scott.DEPT;select count(*) from scott.DEPT                           *ERROR at line 1:ORA-00942: table or view does not exist
12、 导入scott用户
[oracle@xqzt ~]$ impdp dp/dp@pdborcl directory=dp_dir dumpfile=scott_pdborcl.dmp logfile=scott_pdborcl_imp.log schemas=scottImport: Release 12.1.0.2.0 - Production on Thu Dec 10 09:39:02 2015Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit ProductionWith the Partitioning, OLAP, Advanced Analytics and Real Application Testing optionsMaster table "DP"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloadedStarting "DP"."SYS_IMPORT_SCHEMA_01":  dp/********@pdborcl directory=dp_dir dumpfile=scott_pdborcl.dmp logfile=scott_pdborcl_imp.log schemas=scott Processing object type SCHEMA_EXPORT/USERProcessing object type SCHEMA_EXPORT/SYSTEM_GRANTProcessing object type SCHEMA_EXPORT/ROLE_GRANTProcessing object type SCHEMA_EXPORT/DEFAULT_ROLEProcessing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMAProcessing object type SCHEMA_EXPORT/TABLE/TABLEProcessing object type SCHEMA_EXPORT/TABLE/TABLE_DATA. . imported "SCOTT"."DEPT"                              6.023 KB       4 rows. . imported "SCOTT"."EMP"                               8.773 KB      14 rows. . imported "SCOTT"."SALGRADE"                          6.023 KB      10 rows. . imported "SCOTT"."BONUS"                                 0 KB       0 rowsProcessing object type SCHEMA_EXPORT/TABLE/INDEX/INDEXProcessing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINTProcessing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICSProcessing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINTProcessing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICSProcessing object type SCHEMA_EXPORT/STATISTICS/MARKERJob "DP"."SYS_IMPORT_SCHEMA_01" successfully completed at Thu Dec 10 09:39:06 2015 elapsed 0 00:00:04[oracle@xqzt ~]$

13、 测试导入结果

SQL> select count(*) from scott.DEPT;  COUNT(*)----------     4

导入成功!


数据 用户 数据库 文件 权限 目录 路径 测试 成功 容器 切换 不同 有效 传统 参数 同时 多个 完整性 实例 密码 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 互联网科技企业 互联网通讯科技 西安互联网科技 丰台科技园 互联网 易通互联网络科技有限公司 上海致骋互联网科技 无锡溥仪互联网科技有限公司 恒生科技互联网指数分析 安控科技rtu产品工业互联网 西藏七维空间互联网科技有限公司 剑昆互联网络科技有限公司临桂 河南猎农互联网科技有限公司 移动互联网年度科技创新 互联网行业科技股 互联网时代的科技公司 中天科技中国工业互联网 互联网高科技行业有哪些企业 网互联网络科技 瑞安市蟠桃会互联网科技有限公司 互联网的黑科技实验室 广东万易互联网科技有限公司惠州分公司 互联网科技公司华为 苏州大垚互联网科技 互联网科技公司做什么 北京华百购互联网科技有限公司 互联网科技有哪些公司 移动互联网科技公司 领航科技大厦互联网公司 互联网科技包装股份有限公司上市 东风日产互联网科技公司叫什么
0