您的位置:首页 > 其它

数据泵简单导入导出

2017-01-04 11:22 155 查看
1.创建测试用户并赋予dba权限:

create user scott identified by tiger ;
grant connect,resource,dba to scott;
2.在该用户下创建测试表(可以用sys 也可以用scott):

create table test1 (id int) ;
3.插入上万条数据:

insert into scott.test1 values(1);
 insert into test1 select * from test1;//可以把这条命令重复运行几次。主要作用是插入数据。
commit;
4.简单看下这挑expdp 导出命令:
expdp scott/tiger directory=data_pump_dir  \
> tables = test1 dumpfile=scott.dump


directory=data_pump_dir :代表导出文件的目录
tables = test1 :代表要导出的是 scoot 的test1 表
dumpfile =scott.dump : 导出文件名是 scott.dump

注意一点:

因为这里 scott 是 dba权限,所以对 data_pump_dir 有读写权限。如果不是dba权限用户,则会报错:
ORA-39002
ORA-39070:无法打开日志文件
ORA-39087
碰到这种问题:需要给予 读写权限: 语句:grantread,write on directory
data_pump_dir
to XX; XX代表当前用户,我这里是scott

5.导出成功后:

Starting "SCOTT"."SYS_EXPORT_TABLE_01":  scott/******** directory=data_pump_dir tables=test1 dumpfile=scott.dump
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 0 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
. . exported "SCOTT"."TEST1"                                 0 KB       0 rows
Master table "SCOTT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:
/u02/app/oracle/product/11.2.0/db_home/rdbms/log/scott.dump
Job "SCOTT"."SYS_EXPORT_TABLE_01" successfully completed at Sun Jan 8 21:54:09 2017 elapsed 0 00:00:16
进入
/u02/app/oracle/product/11.2.0/db_home/rdbms/log/
发现了-rw-r----- 1 oracle asmadmin  86016 Jan  8 21:54 scott.dump 文件。

同时还有(如果你不指定日志名的话)默认创建的export.log --

具体如下:

-rw-r----- 1 oracle asmadmin  86016 Jan  8 21:54 scott.dump
-rw-r--r-- 1 oracle asmadmin   1127 Jan  8 21:54 export.log
------------------------------------------华丽分割线------------------------------------------------------------------------------------华丽分割线------------------------------------------

6. 现在drop 掉 test1 表并且查看发现表已经被删除。

SQL> drop table test1 ;

Table dropped.
SQL> select * from test1;
select * from test1
*
ERROR at line 1:
ORA-00942: table or view does not exist


7. 用impdp命令恢复:

导入的时候命令很像,只需要把expdp 换成impdp就可以了:

impdp scott/tiger directory=data_pump_dir  tables = test1 dumpfile=scott.dump
结果如下:导入
[oracle@rac1 ~]$ impdp scott/tiger directory=data_pump_dir  tables = test1 dumpfile=scott.dump

Import: Release 11.2.0.4.0 - Production on Sun Jan 8 22:07:59 2017

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, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
Master table "SCOTT"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "SCOTT"."SYS_IMPORT_TABLE_01":  scott/******** directory=data_pump_dir tables=test1 dumpfile=scott.dump
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "SCOTT"."TEST1"                                 0 KB       0 rows
Job "SCOTT"."SYS_IMPORT_TABLE_01" successfully completed at Sun Jan 8 22:08:12 2017 elapsed 0 00:00:11


备注:

1.直接在服务器端操作。

2.运行的时候后台会有一张历史表。

3.select job_name,operation,state from dba_datapump_jobs ;

4.导出发起后,其实是在后台进行了。Ctrl +C也无法打断 


6. 如果不想导了,先 ctrl+c  然后 Stop _job =immediate适用于单线程的,不具备普适性。
    kill job 
7.ORA-39002:操作无效
    ORA-39000:  转储文件说明错误

场景:

8.临时表的名称就是 job 名称。




9562
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: