數據泵expdp、impdp導出導入的方法

exp、imp&expdp、impdp兩組工具的區別:

1、exp和imp是客戶端工具程序,它們既可以在客戶端使用,也可以在服務端使用。expdp和impdp是服務端的工具程序,他們只能在oracle服務端使用,不能在客戶端使用。

2、imp只適用於exp導出的文件;impdp只適用於expdp導出的文件。

3、對於10g以上的服務器,使用exp通常不能導出0行數據的空表,而此時必須使用expdp導出。

4、導入導出的速度不同,數據泵是並行執行,速度快。

5、通過設定數據庫版本號,數據泵可以兼容老版本的數據庫系統。

 

數據泵導入導出:

1、查詢原有邏輯目錄

select * from dba_directories;

2、新建邏輯目錄(第一次進行導入導出操作,需要新建;如果不是第一次,可以使用已有的邏輯目錄)

create directory dump_dir as '/home/oracle/dbdmp';

dump_dir:邏輯目錄名

/home/oracle/dbdmp:實際地址

3、創建大文件表空間

create bigfile tablespace Student

datafile '/home/oracle/tablespace/Student.dbf'  size 100G  AUTOEXTEND ON NEXT 2G MAXSIZE UNLIMITED;

3.1、參數說明

bigfile:大文件

Student:表空間名稱

datafile:指定數據文件的路徑爲/home/oracle/tablespace/Student.dbf。

size 100G:指定數據文件的大小

AUTOEXTEND ON NEXT 2G MAXSIZE UNLIMITED:表空間自動擴展,自動擴展的大小是2G,不限制擴展最大值

4、創建用戶

create user stu identified by s123456 default tablespace Student temporary tablespace temp;

創建用戶stu,密碼s123456,表空間爲Student,臨時表空間爲temp

5、爲用戶賦權

grant connect,resource,unlimted tablespace,imp full database,exp full database,create view,create procedure,create trigger,create database link to stu;

5.1、參數說明

Connect:能夠連接到Oracle數據庫中,並在對其他用戶的表有訪問權限時,做SELECT、UPDATE、INSERTT等操作
resource:能在自己的方案中創建表、序列、視圖等
unlimted tablespace:用戶可以在其他表空間裏隨意建表

imp full database,exp full database:給用戶全庫導出和全庫導入的角色權限

create view,create procedure,create trigger,create database link:創建視圖、過程、觸發器和DBLink

 

6、用戶賦予在指定目錄的操作權限,最好以system等管理員賦予

grant read,write on directory dump_dir to stu;

 

7、通過SSH進入進入服務器

找到相應的路徑 cd /home/oracle/dbdmp

輸入指令

df -h   查看資源使用量

su – oracle   進入系統的oracle用戶

 

8、導出expdp

1)導出用戶

expdp scott/tiger@orcl schemas=scott dumpfile=expdp.dmp directory=dump_dir 

2)導出emp,dept表

expdp scott/tiger@orcl tables=emp,dept dumpfile=expdp.dmp directory=dump_dir

3)按查詢條件導出emp表

expdp scott/tiger@orcl directory=dump_dir dumpfile=expdp.dmp tables=emp query=’where deptno=20’

4)按表空間導

expdp system/manager@orcl directory=dump_dir dumpfile=tablespace.dmp tablespaces=temp,example

5)導整個數據庫

expdp system/manager@orcl directory=dump_dir dumpfile=full.dmp full=y

8.1、expdp參數說明

expdp [用戶名]/[密碼]@[服務名]

schemas=[用戶名]

dumpfile=[導出數據庫文件(可自命名)]

directory=[邏輯目錄名:用於轉儲文件和日誌文件的目錄對象]

logfile=[指定日誌文件名(可自命名)]
full=[導出整個數據庫:n/y]

tablespaces=[標識要導出的表空間的列表]

version=[要導出的對象版本]

 

9、導入impdp

1)導入用戶(從用戶scott導入到用戶scott)

impdp scott/tiger@orcl directory=dump_dir dumpfile=expdp.dmp schemas=scott

2)導入表(從scott用戶中把表dept和emp導入到system用戶中)

impdp system/manager@orcl directory=dump_dir dumpfile=expdp.dmptables=scott.dept,scott.emp remap_schema=scott:system

3)導入表空間

impdp system/manager@orcl directory=dump_dir dumpfile=tablespace.dmp tablespaces=example

4)導入數據庫

impdb system/manager@orcl directory=dump_dir dumpfile=full.dmp full=y

5)追加數據

impdp system/manager@orcl directory=dump_dir dumpfile=expdp.dmp schemas=systemtable_exists_action

 9.1、impdp參數說明

1.USERID:命令行的第一個參數

2.DIRECTORY:轉儲文件和日誌文件存放的目錄

3.DUMPFILE:目標轉儲文件

4.LOGFILE:日誌文件

5.FULL:指定全庫導出 FULL={Y | N}

6.CONTENT:指定要導出的數據,默認爲ALL

   CONTENT={ALL|DATA_ONLY|METADATA_ONLY}

   ALL:導出對象定義及所有數據

   DATA_ONLY:只導出對象數據

   METADATA_ONLY:只導出對象定義

7.SCHEMAS:指定執行方案模式導出,默認爲當前用戶模式

8.TABLES:指定表模式導出

9.TABLESPACES:按表空間模式導出

10.PARALLEL:並行,指定執行導出操作的並行進程個數,默認值爲1

11.INCLUDE:指定導出時要包含的對象類型及相關對象

     INCLUDE = object_type[:name_clause] [,… ]

     eg:INCLUDE=TABLE:"IN(SELECT TABLE_NAME FROM CSB_BFB)"

12.EXCLUDE:指定導出執行時要排除的對象類型及相關對象

13.NETWORK_LINK:指定數據庫鏈名,如果要將遠程數據庫對象導出到本地例程的轉儲文件中,必須設置該選項

14.TABLE_EXISTS_ACTION={skip|append|truncate|replace},默認爲skip

     skip:如果已存在表,則跳過並處理下一個對象;

     append:爲表增加數據;

     truncate是截斷表,然後爲其增加新數據; 

     replace:刪除已存在表,重新建表並追加數據。

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章