zoukankan      html  css  js  c++  java
  • Oracle 表的导入与导出

    周末任务:
    将一个表从一个库导到另一个库
    大致思路:用expdp 将表从一个实例导出 ,再用impdp将导出的 .dmp文件导入到另一个实例
    1.在实例 orcl 中准备一个用于导出的表:
    进入实例为orcl的数据库: export ORACLE_SID=orcl
    建用户:SQL> create user orcl_user identified by 123 default tablespace table_test;

    赋予dba权限:SQL> grant dba to orcl_user;
    建一个directory目录:
    SQL> create directory dir as '/tmp/';
    把这个目录的读写权限给予用户:
    SQL> grant read,write on directory dir to orcl_user;


    接下来可以登录orcl_user用户建表:
    sqlplus orcl_user/123
    SQL> create table orcl_table as select * from dba_users;

    导出:
    oracle@admin ~]$ expdp orcl_user/123 dumpfile=test.dmp logfile=test.log directory=dir tables=orcl_table

    Export: Release 11.2.0.4.0 - Production on Wed Dec 18 07:55:51 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 "ORCL_USER"."SYS_EXPORT_TABLE_01": orcl_user/******** dumpfile=test.dmp logfile=test.log directory=dir tables=orcl_table
    Estimate in progress using BLOCKS method...
    Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
    Total estimation using BLOCKS method: 64 KB
    Processing object type TABLE_EXPORT/TABLE/TABLE
    . . exported "ORCL_USER"."ORCL_TABLE" 14.46 KB 33 rows
    Master table "ORCL_USER"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
    ******************************************************************************
    Dump file set for ORCL_USER.SYS_EXPORT_TABLE_01 is:
    /tmp/test.dmp
    Job "ORCL_USER"."SYS_EXPORT_TABLE_01" successfully completed at Wed Dec 18 07:55:56 2019 elapsed 0 00:00:04

    到此,导出表成功


    2.在实例名为oorl的数据库中做导入的相关准备
    建用户:
    SQL> create user oorl_user identified by 123 default tablespace test;
    赋权限(dba权限和对directory的读写权限)
    SQL> grant dba to oorl_user;


    SQL> grant read,write on directory dir to oorl_user;

    下面开始做impdp导入:

    1).在导入前因将要导入的表中有统计信息,会报ORA-39154的错,故在将imp_full_database的权限授予要导入表的用户:

    SQL> grant imp_full_database to oorl_user;
    2) impdp命令:
    oracle@admin ~]$ impdp oorl_user/123 directory=dir dumpfile=test.dmp logfile=imp.log p.log remap_tablespace=table_test:test remap_schema=orcl_user:oorl_user

    Import: Release 11.2.0.4.0 - Production on Wed Dec 18 08:10:40 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
    Master table "OORL_USER"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
    Starting "OORL_USER"."SYS_IMPORT_FULL_01": oorl_user/******** directory=dir dumpfile=test.dmp logfile=imp.log remap_tablespace=table_test:test remap_schema=orcl_user:oorl_user
    Processing object type TABLE_EXPORT/TABLE/TABLE
    Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
    . . imported "OORL_USER"."ORCL_TABLE" 14.46 KB 33 rows
    Job "OORL_USER"."SYS_IMPORT_FULL_01" successfully completed at Wed Dec 18 08:10:42 2019 elapsed 0 00:00:01


    到此导入成功

    3.验证是否将orcl中的表导入了oorl中:
    在orcl中
    SQL> select count(*) from orcl_user.orcl_table;

    COUNT(*)
    ----------
    33



    在oorl中:
    SQL> select count(*) from oorl_user.orcl_table;

    COUNT(*)
    ----------
    33


    验证成功





    3.实验中出现的错误

    当出现ORA—39154错时,要给用户赋予imp_full_database 的权限(有统计信息时)

    grant imp_full_database to test;

    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
    Master table "TEST"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
    Starting "TEST"."SYS_IMPORT_FULL_01": test/******** directory=dir dumpfile=t1.dmp logfile=test.log remap_tablespace=table_test:test remap_schema=user2:test
    Processing object type TABLE_EXPORT/TABLE/TABLE
    Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
    . . imported "TEST"."T1" 8.457 MB 87170 rows
    Job "TEST"."SYS_IMPORT_FULL_01" successfully completed at Wed Dec 18 07:05:56 2019 elapsed 0 00:00:01

  • 相关阅读:
    ENode框架Conference案例分析系列之
    ENode框架Conference案例分析系列之
    ENode框架Conference案例分析系列之
    ENode 2.6 架构与设计简介以及全新案例分享
    C#分布式消息队列 EQueue 2.0 发布啦
    EQueue 2.0 性能测试报告
    EQueue文件持久化消息关键点设计思路
    213.家庭账务管理信息系统
    212.基于DCT变换的水印算法模拟
    211.哈希表实现活期储蓄账目管理系统
  • 原文地址:https://www.cnblogs.com/zhanglei97/p/12082509.html
Copyright © 2011-2022 走看看