使用empdp和impdp匯出和匯入資料庫的表

2021-08-21 11:53:16 字數 3736 閱讀 2000

資料幫浦技術比原來匯入/匯出(imp,exp)技術快15-45倍。速度的提高源於使用了並行技術來讀寫匯出轉儲檔案。此命令只可用在服務端,客戶端無法使用。

1.開啟sql plus

首先需要輸入使用者名稱和密碼進行登入;

建立乙個directory物件:create directory dpdata1 as 'd:\test\dump';

然後檢視當前例項下有哪些匯出目錄可使用:select * from dba_directories;

最後登入乙個管理員的賬戶來給目前的賬戶賦予讀寫的許可權:grant read,write on directory dpdata1 to scott;

若想賦予全部的許可權即管理員許可權:grant dba to scott;

若重新建立乙個新使用者:create user username identified by password;

給新使用者賦予登入的許可權:grant connect,resource to username;

2.啟用和禁用主鍵等

type code

type description

acts on level

ccheck on a table

column

oread only on a view

object

pprimary key

object

rreferential aka foreign key

column

uunique key

column

vcheck option on a view

object

--刪除所有主鍵約束 的sql** 

select 'alter table '||table_name||' drop constraint '||constraint_name||';' from user_constraints where constraint_type='r'

--alter table emp drop constraint emp_pk ;

--禁用所有主鍵約束的sql**

select 'alter table '||table_name||' disable constraint '||constraint_name||';' from user_constraints where constraint_type='r'

--alter table emp disable constraint emp_pk ;

--啟用所有主鍵約束的sql**

select 'alter table '||table_name||' enable constraint '||constraint_name||';' from user_constraints where constraint_type='r'

--alter table emp enable constraint emp_pk ;

禁用掉主鍵等後會使匯入匯出的速度提高。

3.匯出資料

按表匯出(可單個或多個):

expdp scott/admin@orcl directory=dpdata1 dumpfile=expdp.dmp tables=bonus,emp,dept

結尾不要加分號;

按使用者匯出:expdp scott/admin@orcl directory=dpdata1 dumpfile=expdp.dmp schemas=scott

匯出所有所有表:expdp scott/admin@orcl directory=dpdata1 dumpfile=expdp.dmp full=y

4.匯入資料

impdp yyb/yyb@orcl directory=dpdata1 dumpfile=expdp.dmp remap_schema=scott:yyb exclude=user(使用者已存在,最後不要加分號)

impdp yyb/yyb@orcl directory=dpdata1 dumpfile=expdp.dmp remap_schema=scott:yyb//使用者不存在;

從scott使用者匯入到yyb使用者。

5.拓展:

查詢oracle表是否有觸發器:

select * from user_triggers where table_owner = '***' and table_name = upper('table_name');

匯出資料

1)按使用者導

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

2)並行程序parallel

expdp scott/tiger@orcl directory=dpdata1 dumpfile=scott3.dmp parallel=40 job_name=scott3

3)按表名導

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

4)按查詢條件導

expdp scott/tiger@orcl directory=dpdata1 dumpfile=expdp.dmp tables=emp query='where deptno=20';

5)按表空間導

expdp system/manager directory=dpdata1 dumpfile=tablespace.dmp tablespaces=temp,example;

6)導整個資料庫

expdp system/manager directory=dpdata1 dumpfile=full.dmp full=y;

還原資料

1)導到指定使用者下

impdp scott/tiger directory=dpdata1 dumpfile=expdp.dmp schemas=scott;

2)改變表的owner

impdp system/manager directory=dpdata1 dumpfile=expdp.dmp tables=scott.dept remap_schema=scott:system;

3)匯入表空間

impdp system/manager directory=dpdata1 dumpfile=tablespace.dmp tablespaces=example;

4)匯入資料庫

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

5)追加資料

impdp system/manager directory=dpdata1 dumpfile=expdp.dmp schemas=system table_exists_action

6刪除資料

truncate table test;

truncate與delete的異同:

truncate table 在功能上與不帶 where 子句的 delete 語句相同:二者均刪除表中的全部行。但 truncate table 比 delete 速度快,且使用的系統和事務日誌資源少。

delete 語句每次刪除一行,並在事務日誌中為所刪除的每行記錄一項。truncate table 通過釋放儲存表資料所用的資料頁來刪除資料,並且只在事務日誌中記錄頁的釋放。

truncate table 刪除表中的所有行,但表結構及其列、約束、索引等保持不變。新行標識所用的計數值重置為該列的種子。如果想保留標識計數值,請改用 delete。

oracle中的empdp和impdp簡單記錄

使用expdp和impdp時應該注意的事項 exp和imp是客戶端工具程式,它們既可以在客戶端使用,也可以在服務端使用。expdp和impdp是服務端的工具程式,他們只能在oracle服務端使用,不能在客戶端使用。imp只適用於exp匯出的檔案,不適用於expdp匯出檔案 impdp只適用於expd...

使用expdp和impdp遠端匯入匯出庫

tnames.ora增加 html view plain copy orcl description address list address protocol tcp host 遠端主機ip port 1521 connect data service name 遠端服務名 html view p...

oracle expdp和impdp使用例子

情景 由於生產需求,需要把rmtel使用者的資料完全複製乙份給rmtel xzy,但排除rmtel使用者 cab jjxport tab t servicexx tb crossconnection tb link tb card tb physicalcontainer tb port 這些表。也...