1. 程式人生 > >oracle 資料庫(PL/SQL)的匯入匯出

oracle 資料庫(PL/SQL)的匯入匯出

1,這裡介紹兩種資料庫匯入匯出方式,分別是imp/exp與impdp/expdp(資料泵)

2.先介紹一下imp/exp

imp(需要建立表空間,管理員身份執行)

-------首先建立表空間 create tablespace 表空間名 logging datafile '表空間儲存路徑 +表空間名.dbf' size 200m autoextend on next 200m maxsize unlimited --自動拓展,大小無限 extent management local;--本地管理,對應的有uniform管理,統一大小分配(UNIFORM)則是由使用者指定extents大小,預設1M大小 ------建立使用者 create user 使用者名稱
identified by 密碼 default tablespace 表空間名;
-----給使用者授權 grant resource,connect,dba to 使用者名稱;--不同的角色對應不同的許可權,resource開發人員許可權,connect典型的終端使用者角色,dba為資料庫建立者(具體有好幾個人可設定許可權,如exp_full_database,  --擁有匯出資料庫的許可權,imp_full_database  )
---匯入資料庫【命令視窗中執行】 imp 使用者名稱/密碼
@資料庫fromuser= 匯出方 touser= 匯入方 rows=y indexes=y commit=y buffer=65536 feedback=100000 ignore=n file=匯入的dmp檔案 .dmp log= F:\日誌檔案.log----y是yes,n是no
3,exp匯出 exp 使用者名稱/密碼 @資料庫 rows=y indexes=y compress=n buffer=65536 feedback=100000 file= 匯出.dmp
log= 匯出.log

4,匯入指定表 imp 使用者名稱/密碼 @資料庫 fromuser= 匯出方 touser= 匯入方 rows=y indexes=y commit=y buffer=65536 feedback=100000 ignore=n file= 匯入的dmp檔案 .dmp tables=(k_0001,k_0002) log=F:\匯出.log
--檢視使用者擁有那些角色
select * from dba_role_privs a where a.grantee='XCJ01';
--或
select * from dba_sys_privs a where a.grantee='XCJ01';
--檢視角色擁有哪些許可權
select ROLE, PRIVILEGE from role_sys_privs where role='RESOURCE';   --RESOURCE,CONNECT,DBA
--或 
select grantee,privilege from dba_sys_privs where grantee='RESOURCE';


--為使用者取消角色
revoke resource from XCJ01;
--為使用者取消許可權
revoke unlimited tablespace from XCJ01;


--檢視Oracle版本
select * from v$version where rownum <=1;
3.expdp/impdp(與imp比較) 1、把使用者usera的物件匯入到userb 先建立目錄 create directory dir_dp as 'D:\dbbak'; 
然後匯入如下,其他和imp類似 impdp system/password directory=expdp dumpfile=back.dmp remap_schema='usera':'userb' logfile=backlog.log

 2、更改表空間

  用exp/imp,想要更改表空間,需要手動處理,如alter table xxx move tablespace_new之類的操作,而是用impdp只要用:

  remap_tablespace='tablespace_old' : 'tablespace_new'

  3、當制定多個表的時候

  exp/imp用法:tables('table1','table2','table3')

  expdp/impdp用法:tables='table1','table2','table3'

 

  4、是否要匯出資料行

  exp rows=y,匯出資料行,rows=n不匯出資料行

  expdp content(all:物件+資料行,data_only:只匯出物件,metadata_only:只匯出資料的記錄

資料來源:

https://www.cnblogs.com/zhengcheng/p/4201567.html

https://note.youdao.com/share/?id=bb8dd43350746e619a61d3c6d3e09c82&type=note#/