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

          1,需要为pdb添加tansnames

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

 

数据泵导入导出例子

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

登录cdb,查看pdb,

SQL> show con_name

CON_NAME
------------------------------
CDB$ROOT SQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDBORCL MOUNTED SQL> alter pluggable database all open; Pluggable database altered. SQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDBORCL READ WRITE NO

切换到pdborcl

SQL> alter salter session set container=pdborcl ;

Session altered.

SQL>
2、查看示例用户scott,以后的schema级别导入导出就使用该用户的数据。

    参考:Oracle 12c 添加scott用户

SQL> col tabselect owner, table_name from dba_tables where owner='SCOTT';

OWNER                   TABLE_NAME
------------------------------ ----------------------------------------
SCOTT SALGRADE
SCOTT BONUS
SCOTT EMP
SCOTT 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 pdborcl

TNS Ping Utility for Linux: Version 12.1.0.2.0 - Production on 10-DEC-2015 09:10:34

Copyright (c) 1997, 2014, Oracle.  All rights reserved.

Used parameter files:
/data/app/oracle/product/12.1.0/dbhome_1/network/admin/sqlnet.ora Used TNSNAMES adapter to resolve the alias
Attempting 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=scott

Export: Release 12.1.0.2.0 - Production on Thu Dec 10 09:32:05 2015

Copyright (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 Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
Starting "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_DATA
Total estimation using BLOCKS method: 192 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/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing 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 rows
Master table "DP"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for DP.SYS_EXPORT_SCHEMA_01 is:
/home/oracle/scott_pdborcl.dmp
Job "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(*)
----------
4 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=scott

Import: Release 12.1.0.2.0 - Production on Thu Dec 10 09:39:02 2015

Copyright (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 Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
Master table "DP"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded
Starting "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/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 "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 rows
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/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/STATISTICS/MARKER
Job "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

导入成功!

Oracle 12c pdb的数据泵导入导出的更多相关文章

  1. (Oracle)DDL及其数据泵导入导出(impdp/expdp)

    create tablespace ybp_dev datafile 'G:\app\Administrator\oradata\health\ybp_dev1.dbf' size 10m autoe ...

  2. Oracle基础 exp/imp 数据泵导入/导出 命令

    一.导出方式: 使用exp/imp方式导出数据分为四种方式: 1.表方式导出:一个或多个指定的表,包括表的定义.表数据.表的所有者授权.表索引.表约束,以及创建在该表上的触发器.也可以只导出结构,不导 ...

  3. Oracle 数据泵导入导出总结

    Oracle 数据泵(IMPDP/EXPDP)导入导出总结 Oracle数据泵导入导出是日常工作中常用的基本技术之一,它相对传统的逻辑导入导出要高效,这种特性更适合数据库对象数量巨大的情形,因为我日常 ...

  4. 【EXPDP/IMPDP】ORACLE数据泵导入导出案例(expdp & impdp)

    概要: 因项目需要,通常需要将生产库下的部分数据抽取并恢复到测试库上 本文主要介绍数据泵导入导出的几种情况以及错误处理 案例环境: rhel-server-6.5-x86_64 oracle 11.2 ...

  5. Oracle使用数据泵导入/导出数据(expdp/impdp)

    Oracle使用数据泵导入/导出数据(expdp/impdp) A电脑上的操作(expdp数据导出) 运行cmd: 登录数据库,输入命令:sqlplus 使用管理员角色登录需要在用户名后加" ...

  6. 【EXPDP/IMPDP】数据泵导入导出遇到目录没有权限问题

    当执行数据泵导出的时候,报了如下错误: ORA-39002: invalid operation ORA-39070: Unable to open the log file. ORA-39087: ...

  7. oracle中使用impdp数据泵导入数据提示“ORA-31684:对象类型已经存在”错误的解决

    转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/47448751 本文出自[我是干勾鱼的博客] oracle中使用impdp数据泵导 ...

  8. 【Oracle】数据泵导入导出

    数据泵 expdp导出 nohup expdp  system/******** dumpfile=lysb_20121113_%U.dmp directory=dmp_dir schemas=sco ...

  9. Oracle数据泵导入导出数据,建立表空

    Oracle11g 数据导入到oracle10g 中:1.在oracle11g 服务器命令行中用expdp 导出数据expdp ts/ts@orcl directory=expdp_dir dumpf ...

随机推荐

  1. Ubuntu 16.4 安装anaconda 详细教程

    下载 官方下载地址:https://www.continuum.io/downloads 所有安装包地址:https://repo.continuum.io/archive/ 这里使用 Python ...

  2. 安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom

    Drawable rightDrawable = getResources().getDrawable(R.drawable.icon_new); //调用setCompoundDrawables时, ...

  3. Linux 下安装 MATLAB

    MATLAB是美国MathWorks公司出品的商业数学软件,主要用于算法开发.数据可视化.数据分析以及数值计算的高级技术计算语言和交互式环境,是一款优秀而又强大的数学软件. 本文基于 Deepin 1 ...

  4. 利用mysqldump 实现每天备份方案

    1.创建单独的导出导入数据库帐号 grant SELECT, RELOAD, SHOW DATABASES, LOCK TABLES on game to jackluo@localhost iden ...

  5. js的"|"

    3|4 转换为二进制之后011|100  相加得到111=7 4|4 转换为二进制之后100 |100  相加得到1000=8 8|3 转换为二进制之后1000 |011  相加得到1011=11 以 ...

  6. width:100vh与min-height:calc(100vh + 51px)

    vh:相对于视窗的高度,那么vw:则是相对于视窗的高度. “视区”所指为浏览器内部的可视区域大小,即window.innerWidth/window.innerHeight大小,不包含任务栏标题栏以及 ...

  7. 6.Django与Ajax

    Ajax 文件夹为Ajaxdemo 向服务器发送请求的途径: 1.浏览器地址栏,默认get请求: 2.form表单: get请求 post请求 3.a标签,超链接(get请求) 4.Ajax请求 特点 ...

  8. 二分搜索-poj1064

    题目大概意思是:给你N个长度的电缆,需要你编写程序 将它分割成 K 根长度相等的小电缆.而我们的目的就是要求出分割出的 最大长度 可以为多少.此处可以应用二分搜索的知识来实现查找最终长度. 代码实现 ...

  9. UVa140 Bandwidth 【最优性剪枝】

    题目链接:https://vjudge.net/contest/210334#problem/F  转载于:https://www.cnblogs.com/luruiyuan/p/5847706.ht ...

  10. 李宏毅机器学习笔记2:Gradient Descent(附带详细的原理推导过程)

    李宏毅老师的机器学习课程和吴恩达老师的机器学习课程都是都是ML和DL非常好的入门资料,在YouTube.网易云课堂.B站都能观看到相应的课程视频,接下来这一系列的博客我都将记录老师上课的笔记以及自己对 ...