数据库

 首页 > 数据库 > MySql > 以交互方式使用exp/imp的演示

以交互方式使用exp/imp的演示

分享到:
【字体:
导读:
         摘要:总所周知,用expimp对数据库进行逻辑备份,包括表,用户,整个数据库,我们通常所熟悉的是使用命令行指定参数的方式来做的。下面我来演示一下不太常用的以交互方式的操作,操作很简单,就是只要输入expimp的命令,以交互方式提供导入导出所需的参数来完成。虽然这种方式没有实际的应用意义,但作为Oracle提供的一种方法,我们...

以交互方式使用exp/imp的演示
总所周知,用exp/imp对数据库进行逻辑备份,包括表,用户,整个数据库,我们通常所熟悉的是使用命令行指定参数的方式来做的。下面我来演示一下不太常用的以交互方式的操作,操作很简单,就是只要输入exp/imp的命令,以交互方式提供导入导出所需的参数来完成。虽然这种方式没有实际的应用意义,但作为Oracle提供的一种方法,我们也是有必要熟悉一下的。

环境:Oracle 10.2.0.1/Linux Red Hat 5.3

一、单表导出导入测试

--创建测试表
[oracle@ora10g ~]$ sqlplus zlm/zlm
SQL> select username,default_tablespace from dba_users where username='ZLM';

USERNAME                       DEFAULT_TABLESPACE
------------------------------ ------------------------------
ZLM                            ZLM

SQL> create table t1 as select * from dba_objects;

Table created.

SQL> create table t2 as select * from user_objects;

Table created.

SQL> select count(*) from t1;

  COUNT(*)
----------
     50355

SQL> select count(*) from t2;

  COUNT(*)
----------
         2

SQL> !

注意,由于之前指定过zlm用户的缺省表空间为ZLM,因此这2个测试表是会创建到ZLM表空间中去的

--执行导出t1表
[oracle@ora10g ~]$ exp

Export: Release 10.2.0.1.0 - Production on 11 11:04:17 2014

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


Username: zlm
Password: 

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Enter array fetch buffer size: 4096 > 8192

Export file: expdat.dmp > t1.dmp    -指定导出的dmp文件名

(1)E(ntire database), (2)U(sers), or (3)T(ables): (2)U > t    --可以输入“T”,也可以输入“3”

Export table data (yes/no): yes > 

Compress extents (yes/no): yes > 

Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set

About to export specified tables via Conventional Path ...
Table(T) or Partition(T:P) to be exported: (RETURN to quit) >     --如果不输入表名直接回车表示会退出的,不导出任何表

Export terminated successfully without warnings.
[oracle@ora10g ~]$ exp    --由于刚才直接退出了,再重新导一次

Export: Release 10.2.0.1.0 - Production on 11 11:05:00 2014

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


Username: zlm
Password: 

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Enter array fetch buffer size: 4096 > 8192    --指定buffer,默认是4k,这里指定了8k,实际使用时还可以设置更大的值,如1000000,即10M

Export file: expdat.dmp > t1.dmp

(1)E(ntire database), (2)U(sers), or (3)T(ables): (2)U > 3

Export table data (yes/no): yes > 

Compress extents (yes/no): yes > 

Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set

About to export specified tables via Conventional Path ...
Table(T) or Partition(T:P) to be exported: (RETURN to quit) > t1    --指定需要导出的t1测试表

. . exporting table                             T1      50355 rows exported
Table(T) or Partition(T:P) to be exported: (RETURN to quit) >     --没有其他想导出的表,就回车退出

Export terminated successfully without warnings.
[oracle@ora10g ~]$ exit
exit

--删除测试表t1
SQL> drop table t1 purge;

Table dropped.

SQL> select count(*) from t1;
select count(*) from t1
                     *
ERROR at line 1:
ORA-00942: table or view does not exist

--执行导入t1表
SQL> !
[oracle@ora10g ~]$ imp

Import: Release 10.2.0.1.0 - Production on 11 11:06:12 2014

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

Username: zlm
Password: 

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

Import file: expdat.dmp > t1.dmp    --指定刚才由exp生成的dmp文件作为导入的源

Enter insert buffer size (minimum is 8192) 30720>     --指定insert的buffer,直接回车采用默认值30720

Export file created by EXPORT:V10.02.01 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
List contents of import file only (yes/no): no >    --默认是no,如果选择了yes,那么就没有以下3个选项了

Ignore create error due to object existence (yes/no): no > 

Import grants (yes/no): yes > 

Import table data (yes/no): yes > 

Import entire export file (yes/no): no > yes    --由于导出的时候只是对t1表单独的操作,所以选择yes也仅仅是导入t1表而已

. importing ZLM's objects into ZLM
. importing ZLM's objects into ZLM
. . importing table                           "T1"      50355 rows imported
Import terminated successfully without warnings.
[oracle@ora10g ~]$ exit
exit

SQL> select count(*) from t1;

  COUNT(*)
----------
     50355

SQL> !

现在表已经成功地被重新导入到数据库中的zlm用户中,相当于利用了原来对t1表的逻辑备份,对误删除的t1表进行恢复,如果再对已经存在的t1表执行一次导入操作,会发生什么情况呢?

[oracle@ora10g ~]$ imp

Import: Release 10.2.0.1.0 - Production on 11 11:07:12 2014

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

Username: zlm
Password: 

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

Import file: expdat.dmp > t1.dmp

Enter insert buffer size (minimum is 8192) 30720> 

Export file created by EXPORT:V10.02.01 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
List contents of import file only (yes/no): no > yes
(选yes就没有了刚才的3个选项了)
Import entire export file (yes/no): no > yes    --依然是选择导入整个导出文件t1.dmp(即:文件中仅有t1表的逻辑语句)

. importing ZLM's objects into ZLM
. importing ZLM's objects into ZLM
 "CREATE TABLE "T1" ("OWNER" VARCHAR2(30), "OBJECT_NAME" VARCHAR2(128), "SUBO"
 "BJECT_NAME" VARCHAR2(30), "OBJECT_ID" NUMBER, "DATA_OBJECT_ID" NUMBER, "OBJ"
 "ECT_TYPE" VARCHAR2(19), "CREATED" DATE, "LAST_DDL_TIME" DATE, "TIMESTAMP" V"
 "ARCHAR2(19), "STATUS" VARCHAR2(7), "TEMPORARY" VARCHAR2(1), "GENERATED" VAR"
 "CHAR2(1), "SECONDARY" VARCHAR2(1))  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRA"
 "NS 255 STORAGE(INITIAL 6291456 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DE"
 "FAULT) TABLESPACE "ZLM" LOGGING NOCOMPRESS"
. . skipping table "T1"                               

Import terminated successfully without warnings.    

这里虽然提示“无警告地成功地结束了命令”,但并没有执行真正的导入,原因是之前的t1表已经存在,默认如果发生object existance的error,那么导入就会终止,这时候我们可以通过选择“Ignore create error due to object existence (yes/no): no > yes”来解决,这个交互模式中的yes就相当于我们熟悉的命令行中的参数ignore=y,表示使用追加的方式导入,并不会覆盖原来的数据,也不会因为对象已经存在而终止导入

[oracle@ora10g ~]$ imp

Import: Release 10.2.0.1.0 - Production on 11 11:07:38 2014

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

Username: zlm
Password: 
以交互方式使用exp/imp的演示

  • 打酱油

  • 震惊

  • 呵呵


  • 鄙视
标签标签:PHP ,CSS数据库 ,优化
分享到:
ORA-30009: CONNECT BY 操作内存不足
ORA-30009: CONNECT BY 操作内存不足  今天在11g的环境上制造数据碰到ORA-30009: CONNECT BY 操作内存不足,10g开始支持XML后,改为xmltable就可以了。 SQL> drop table t_range purge; SQL> create table t_range (id number not null PRIMARY KEY, test_date date) partition by range (test_date)     (     partit...
Windows下MySQL日志管理(Linux类似)1.1
Windows下MySQL日志管理(Linux类似)1.1为什么要开启数据库的日志 当多个程序都在使用数据库的时候,我们的数据库有时候居然还会挂掉,想找原因?发现没日志可查,各个程序自己的日志又不能找到关键原因。所以要开启数据库的日志系统。 控制日志大小 要开日志前提是要知道怎么控制日志的大小,这是一般日志都要面临的第一...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……