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 名稱。