Oracle 12c 建库后,没有 scott 模式,本篇使用数据泵方式,在12c版本之前数据库中 expdp 导出 scott 模式,并连接 12c 的 pdb 进行 impdp 导入。

目录

1. 在11g版本中数据泵导出

  1.1 创建 directory 目录

  1.2 数据泵导出

  1.3 确认scott用户及权限信息

2. 在12c版本中数据泵导入

  2.1 配置TNSNAMES.ora

  2.2 测试连接PDB

  2.3 执行scott用户及权限信息

  2.4 创建 directory 目录

  2.5 数据泵导入

  2.6 验证数据

1. 在11g版本中数据泵导出

1.1 创建 directory 目录

SQL> select * from dba_directories;

SQL> create directory backup_dir as '/u01/app/oracle/backup';

Directory created.

SQL> grant read,write on directory backup_dir to system;

Grant succeeded.

1.2 数据泵导出

[oracle@henry ~]$ expdp system/oracle directory=backup_dir dumpfile=expdp_scott.dmp logfile=expdp_scott.log schemas=scott

Export: Release 11.2.0.4.0 - Production on Fri May 24 19:53:16 2019

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01": system/******** directory=backup_dir dumpfile=expdp_scott.dmp logfile=expdp_scott.log schemas=scott
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 384 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
. . exported "SCOTT"."A" 5.460 KB 6 rows
. . exported "SCOTT"."ABC" 5 KB 1 rows
. . exported "SCOTT"."DEPT" 5.929 KB 4 rows
. . exported "SCOTT"."EMP" 8.562 KB 14 rows
. . exported "SCOTT"."SALGRADE" 5.859 KB 5 rows
. . exported "SCOTT"."TESTEMP" 8.648 KB 19 rows
. . exported "SCOTT"."BONUS" 0 KB 0 rows
. . exported "SCOTT"."TBA" 0 KB 0 rows
. . exported "SCOTT"."TBS_C" 0 KB 0 rows
Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:
/u01/app/oracle/backup/expdp_scott.dmp
Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at 19:54:28

1.3 确认scott用户及权限信息

用户(模式)导出,要事先知道该用户(模式)在原来数据库中所涉及的表空间、系统权限、对象权限、角色权限等。我们可以通过调用 dbms.metadata 包来获得相关资源。

SQL> select dbms_metadata.get_ddl('USER','SCOTT') from dual;

CREATE USER "SCOTT" IDENTIFIED BY VALUES 'S:F2071AA98BBC32C96BBADA4D194880F30491BAD413C402C5887BF4439B7C;F894844C34402B67'
DEFAULT TABLESPACE "USERS"
TEMPORARY TABLESPACE "TEMP" SQL> select dbms_metadata.get_granted_ddl('OBJECT_GRANT','SCOTT') from dual;
ERROR:
ORA-31608: specified object of type OBJECT_GRANT not found
ORA-06512: at "SYS.DBMS_METADATA", line 5088
ORA-06512: at "SYS.DBMS_METADATA", line 7737
ORA-06512: at line 1 SQL> select dbms_metadata.get_granted_ddl('ROLE_GRANT','SCOTT') from dual; GRANT "CONNECT" TO "SCOTT"
GRANT "RESOURCE" TO "SCOTT"
GRANT "DBA" TO "SCOTT" SQL> select dbms_metadata.get_granted_ddl('SYSTEM_GRANT','SCOTT') from dual; GRANT UNLIMITED TABLESPACE TO "SCOTT" SQL> select dbms_metadata.get_ddl('TABLESPACE','SCOTT') from dual;
ERROR:
ORA-31603: object "SCOTT" of type TABLESPACE not found in schema "SYS"
ORA-06512: at "SYS.DBMS_METADATA", line 5088
ORA-06512: at "SYS.DBMS_METADATA", line 7589
ORA-06512: at line 1

相关报错说明该用户在原来数据库中对应的元数据不存在,直接忽略。将上面的获取到的语句进行整理备用。最后,将导出的文件,拷贝至12c所在的服务器(实验环境的具体路径和11g所在的服务器是一致的)。

2. 在12c版本中数据泵导入

2.1 配置TNSNAMES.ora

在12c的PDB中普通用户无法像非CDB那样直接通过 conn 互切用户(比如在一个PDB中,普通henry用户无法直接切换到其他普通用户),默认在PDB中 sys 用户也无法直接切换到 henry 用户,例如:

SQL> alter session set container=pdb1;

Session altered.

SQL> select username from dba_users where username='HENRY';

USERNAME
------------------------------
HENRY SQL> show user;
USER is "SYS"
SQL> show con_name; CON_NAME
------------------------------
PDB1
SQL> conn henry/henry
ERROR:
ORA-01017: invalid username/password; logon denied Warning: You are no longer connected to ORACLE.

必须配置 tnsnames.ora 连接字符串别名,并通过 sqlplus 命令进行连接。

[oracle@henry ~]$ cd $ORACLE_HOME/network/admin/
[oracle@henry admin]$ vim tnsnames.ora

在tnsnames.ora文件中添加连接字符串

PDB1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = henry)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = PDB1)
)
)

2.2 测试连接PDB

查看当前CDB中的PDB

SQL> show pdbs

    CON_ID CON_NAME     OPEN MODE  RESTRICTED
---------- ------------ ---------- ----------
2    PDB$SEED READ ONLY NO
3    PDB1 READ WRITE NO

当前CDB中只有一个用户PDB:PDB1

因为已经添加过连接字符串,现在尝试连接PDB1

[oracle@henry ~]$ sqlplus henry/henry@pdb1

SQL*Plus: Release 12.2.0.1.0 Production on Fri May 24 21:06:36 2019

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Last Successful login time: Fri May 24 2019 21:04:59 +08:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production SQL> show user;
USER is "HENRY"
SQL> show con_name CON_NAME
------------------------------
PDB1

测试连接成功。

2.3 执行scott用户及权限信息

该语句信息在1.3小节通过 dbms.metadata 包得到。

CREATE USER "SCOTT" IDENTIFIED BY VALUES 'S:F2071AA98BBC32C96BBADA4D194880F30491BAD413C402C5887BF4439B7C;F894844C34402B67'
DEFAULT TABLESPACE "USERS"
TEMPORARY TABLESPACE "TEMP"; GRANT "CONNECT" TO "SCOTT";
GRANT "RESOURCE" TO "SCOTT";
GRANT "DBA" TO "SCOTT";
GRANT UNLIMITED TABLESPACE TO "SCOTT"

2.4 创建 directory 目录

[oracle@henry ~]$ mkdir /u01/app/oracle/backup

12c数据库所在的服务器具体目录路径和11g是一样的(具体路径根据实际情况),backup目录下放着11g数据泵导出来的 scott 模式的dmp文件。

[oracle@henry ~]$ sqlplus sys/oracle@pdb1 as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Fri May 24 20:06:25 2019

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production SQL> show con_name; CON_NAME
------------------------------
PDB1 SQL> select * from dba_directories; SQL> create directory backup_dir as '/u01/app/oracle/backup'; Directory created. SQL> grant read,write on directory backup_dir to system; Grant succeeded.

2.5 数据泵导入

[oracle@henry ~]$ impdp system/oracle@pdb1 directory=backup_dir dumpfile=expdp_scott.dmp logfile=impdp_scott.log schemas=scott

Import: Release 12.2.0.1.0 - Production on Fri May 24 20:12:35 2019

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Master table "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01": system/********@pdb1 directory=backup_dir dumpfile=expdp_scott.dmp logfile=impdp_scott.log schemas=scott
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"."A" 5.460 KB 6 rows
. . imported "SCOTT"."ABC" 5 KB 1 rows
. . imported "SCOTT"."DEPT" 5.929 KB 4 rows
. . imported "SCOTT"."EMP" 8.562 KB 14 rows
. . imported "SCOTT"."SALGRADE" 5.859 KB 5 rows
. . imported "SCOTT"."TESTEMP" 8.648 KB 19 rows
. . imported "SCOTT"."BONUS" 0 KB 0 rows
. . imported "SCOTT"."TBA" 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
Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" completed with 2 error(s) at Fri May 24 20:13:28 2019 elapsed 0 00:00:44

2.6 验证数据

[oracle@henry ~]$ sqlplus scott/tiger@pdb1

SQL*Plus: Release 12.2.0.1.0 Production on Fri May 24 21:16:54 2019

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Last Successful login time: Fri May 24 2019 21:16:43 +08:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production SQL> show user
USER is "SCOTT"
SQL> show con_name CON_NAME
------------------------------
PDB1
SQL> select count(*) from emp; COUNT(*)
----------
14 SQL> select count(*) from dept; COUNT(*)
----------
4

Oracle 12c 如何在 PDB 中添加 SCOTT 模式(数据泵方式)的更多相关文章

  1. Oracle 12c 如何在 PDB 中添加 SCOTT 模式(手工方式)

    Oracle 12c 建库后,没有 scott 模式,本篇使用手工脚本方式,在12c版本中创建 scott 模式及相关表. 目录 1. PDB中创建用户 2. PDB中用户授权 3. PDB中创建表空 ...

  2. Oracle 12c 多租户家族(12c 18c 19c)如何在 PDB 中添加 HR 模式

    Oracle 12c 多租户家族(12c [12.2.0.1].18c [12.2.0.2].19c [12.2.0.3])如何在 PDB 中添加模式:19c (19.3) 手工添加示例 HR 用户 ...

  3. Oracle 12c在SQL Devolper中添加cdb和pdb连接

    Oracle 12c如果按默认流程安装的话会有一个叫orcl的cdb容器和一个叫pdborcld的pdb容器 一.连接名为orcl的cdb容器 连接名:localorcl 用户名:SYS 口令:Ora ...

  4. Oracle 12c在PDB中创建scott/tiger

    scott/tiger一直以来是oracle数据的默认用户,但是跟之前的版本相比,Oracle 12c引入了PDB管理,所以要麻烦一些 下面假设管理员为SYS/Oracle12csys,在orcl实例 ...

  5. 如何在Eclipse中添加Tomcat的jar包

    原文:如何在Eclipse中添加Tomcat的jar包 右键项目工程,点击Java Build Path 点击Add Library,选择Server Runtime 选择Tomcat版本 此时就看到 ...

  6. 如何在Eclipse中添加Servlet-api.jar的方法

    方法一: 点击窗口->首选项->java->构建路径->类路径变量->新建:将你的tomcat目录下的common/lib/servlet.jar加进来.如果你建立了一个 ...

  7. 如何在niosII中添加i2c外设_winday_新浪博客

    如何在niosII中添加i2c外设_winday_新浪博客 如何在niosII中添加i2c外设 winday 摘要:本文说明了如何在niosII添加第三方i2c外设,以供参考. 由于本人使用的Alte ...

  8. Oracle 12C CDB、PDB常用管理命令

    Oracle 12C CDB.PDB常用管理命令 --查看PDB信息(在CDB模式下) show pdbs  --查看所有pdbselect name,open_mode from v$pdbs;  ...

  9. DataGridView 中添加CheckBox和常用处理方式 .

    DataGridView 中添加CheckBox和常用处理方式 文章1 转载:http://blog.csdn.net/pinkey1987/article/details/5267934 DataG ...

随机推荐

  1. php面试笔记(3)-php基础知识-运算符

    本文是根据慕课网Jason老师的课程进行的PHP面试知识点总结和升华,如有侵权请联系我进行删除,email:guoyugygy@163.com 在面试中,考官往往喜欢基础扎实的面试者,而运算符相关的考 ...

  2. ELK logstash 各种报错

    1.logstash 启动后数据传输了,但是 ElasticSearch 中没有生成索引,查看logstash日志,报错如下 [2018-06-08T14:46:25,387][WARN ] [log ...

  3. 使用mysqlfrm恢复frm表结构的方法

    1.mysqlfrm安装 由于mysqlfrm是mysql-utilities工具一部分,那么我们安装mysql-utilities即可,下载好对应的源码包,进行编译安装 shell> wget ...

  4. Webpack之(progressive web application) - PWA中的 Service Workers 是什么

    学习文档:https://webpack.docschina.org/guides/progressive-web-application/ 参考文档:https://developers.googl ...

  5. backgroud图片充满元素的方法

    background-image: url("img/headimg.png"); height: 219px; background-size: 100% 100%; backg ...

  6. 用 Python 分析今年考研形势

    还有5天,就到了考研初试的时间了. ! 尽管今年研招网内部,已经做了优化改善,还是抵挡不住考生们的报名热情(网站崩溃). ​ 2017年考研人数增长至201万人, 2018年则达到238万人, 201 ...

  7. C#模拟POST上传文件帮助类(支持https、http)

    public static int PostFile(string getUrl, CookieContainer cookieContainer, HttpHeader header, string ...

  8. python基础入门之四 —— 列表

    1.格式 [数据1,数据2,数据3,...] 列表可以一次性存多个数据,可以为不同的数据类型 2.下标 从0开始循序向下分配 3.常用函数 查找 index():返回指定数据所在位置下标,不存在就报错 ...

  9. [MongoDB] 使用PHP根据_id字段查询数据

    mongo中的_id是一个objectid对象类型,不管是查询时作为条件,还是列表时展示内容,都需要进行一下抓换 查询时要转为objectid对象 列表时要把对象转成字符串覆盖回_id字段 $filt ...

  10. Android布局管理器-从实例入手学习相对布局管理器的使用

    场景 AndroidStudio跑起来第一个App时新手遇到的那些坑: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103797 ...