zoukankan      html  css  js  c++  java
  • 导入与导出详解

    导出表

    1、导出自己的表

    exp userid=用户名/密码@数据库实例名 tables=(表名1,表名2,..) file=备份路径

    例:exp userid=scott/tiger@orcl tables=(emp,dept) file=d:/scott_emp_dept.dmp

    2、导出其它方案的表

    如果用户要导出其它方案的表,则需要DBA的权限或是exp_full_database的权限,比如system就可以导出scott的表

    exp useris=用户名/密码@数据库实例名 tables=(方案名.表名1,方案名.表名2,..) file=备份路径

    例:exp userid=system/orcl@orcl tables=(scott.emp,scott.dept) file=d:/scott_emp_

    dept2.dmp

    特别说明:备份文件的后缀名一般是.dmp,但是这不是必须的。

    3、导出表的结构

    exp userid=用户名/密码@数据库实例名 tables(表名1,表名2,..) file=备份路径 rows=n

    例:exp userid=system/orcl@orcl tables(scott.emp,scott.dept) file=d:/scott_em

    p_dept.demp rows=n

    4、使用直接导出方式

    exp userid=用户名/密码@数据库实例名 tables(表名1,表名2,..) file=备份路径 direct=y

    例:exp userid=system/orcl@orcl tables(scott.emp,scott.dept) file=d:/scott_em

    p_dept.demp direct=y

    这种方式比默认的常规方式速度要快,当数据量大时,可以考虑使用这样的方法。

    这时需要数据库的字符集要与客户端字符集完全一致,否则会报错。

    导出方案

    导出方案是指使用export工具导出一个方案或是多个方案中的所有对象(表、索引、约束..)和数据,并存放到文件中。

    1、导出自己的方案

    exp 用户名/密码@数据库实例名 owner=所有者 file=备份路径

    例:exp scott/tiger@orcl owner=scott file=d:/scott_owner.dmp

    2、导出其它方案

    如果用户要导出其它方案,则需要dba的权限或者exp_full_database的权限。例如system用户就可以导出任何方案

    exp 用户名/密码@数据库实例名 owner=(所有者1,所有者2,..) file=备份路径

    例:exp system/orcl@orcl owner=scott,system file=d:/system_scott_owner.dmp

    特别注意:如果用户的权限够大,则可一次性导出多外用户的方案。比如system

    导出完整数据库

    需要dba的权限或者exp_full_database的权限。

    exp 用户名/密码@数据库实例名 full=y file=备份路径

    例:exp system/orcl@orcl full=y file=d:/orcl_full.dmp

    导出表

    [oracle@oracle ~]$ exp hr/oracle file=/home/oracle/hr2.dmp TABLES="(employees,departments)";

    Export: Release 11.2.0.4.0 - Production on Thu Jul 12 13:38:07 2018

    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

    Export done in AL32UTF8 character set and AL16UTF16 NCHAR character set

    About to export specified tables via Conventional Path ...

    . . exporting table                      EMPLOYEES        107 rows exported

    . . exporting table                    DEPARTMENTS         27 rows exported

    Export terminated successfully without warnings.

    导出不含约束的表

    exp hr/oracle file=/home/oracle/hr2.dmp TABLES="(employees,departments)" constraints=n

    创建HR2用户

    SYS@VDEDU>create user hr2 identified by oracle;

    赋予权限

    SYS@VDEDU>grant dba to hr2;

    _________________________________________________________________________________________________________________________________

    _________________________________________________________________________________________________________________________________

    导入表

    导入自身表

    imp 用户名/密码@数据库实例名 file=备份路径 tables=(表名1,表名2,..)

    例:imp scott/tiger@orcl file=d:/emp_dept.dmp

    特别注意:如果目的地有相同的表,则导入不成功。

    导入其它方案的表

    需要有dba权限或者imp_full_database的权限。

    imp 用户名/密码@数据库实例名 file=备份路径 tables=(表名1,表名2,..) fromuser=方案名 touser=system

    例:imp system/orcl@orcl file=d:/scott_emp_dept.demp tables=emp,dept fromuser=scott touser=system

    注意:提示成功,但警告,表示此对象有scott导出,而不是当前用户。

    导入方案

    导入自身方案

    imp 用户名/密码@数据库实例名 file=备份路径

    例:imp scott/tiger@orcl file=scott_owner.dmp

    导入其它方案

    需要有dba权限或者imp_full_database权限

    imp 用户名/密码@数据库实例名 file=备份路径 fromuser=方案名 touser=system

    例:imp system/orcl@orcl file=scott.dmp fromuser=scott touser=system

    导入完整数据库

    需要有dba权限或者imp_full_database权限

    imp 用户名/密码@数据库实例名 file=备份路径 full=y

    例:imp system/orcl@orcl file=orcl_full.dmp full=y

    导入表

    imp system/oracle file=hr2.dmp tables=departments fromuser=hr touser=hr2

    [oracle@oracle ~]$ imp system/oracle file=hr2.dmp tables=departments fromuser=hr touser=hr2;

    Import: Release 11.2.0.4.0 - Production on Thu Jul 12 14:01:10 2018

    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

    Export file created by EXPORT:V11.02.00 via conventional path

    Warning: the objects were exported by HR, not by you

    import done in AL32UTF8 character set and AL16UTF16 NCHAR character set

    . importing HR's objects into HR2

    . . importing table                  "DEPARTMENTS"         27 rows imported

    Import terminated successfully without warnings.

    remap_schema当你从A用户导出的数据,想要导入到B用户中去,就使用这个:remap_schema=A:B
    remap_tablespace 与上面类似,数据库对象本来存在于tbs_a表空间,现在你不想放那儿了,想换到tbs_b,就用这个remap_tablespace=tbs_a:tbs_b 结果是所有tbs_a中的对象都会建在tbs_b表空间中。

  • 相关阅读:
    (原创)如何利用UDP协议封装一个数据包
    <acarousel> 轮播图片无法触屏滑动
    Groovy开发语言
    关于ViewStub标签
    关键字transient和Volatile
    Android中Activity启动模式
    Android 开源项目分类汇总
    AtomicInteger的并发处理
    Cygwin: died waiting for dll loading (转载)
    Android知识点(C2DM)
  • 原文地址:https://www.cnblogs.com/kawashibara/p/9351701.html
Copyright © 2011-2022 走看看