exp/imp 多用戶導入導出


創建用戶

創建三個用戶test1,test2,test3及表table1,table2,table3

SQL> create user test1 identified by test1 default tablespace users;

User created.

SQL> grant connect,resource to test1;

Grant succeeded.

SQL> create table test1.table1 as select * from dba_objects;

Table created.

SQL> select count(1) from test1.table1;

  COUNT(1)
----------
     87459
create user test2 identified by test2 default tablespace users;
grant connect,resource to test2;
create table test2.table2 as select * from dba_objects;

create user test3 identified by test3 default tablespace users;
grant connect,resource to test3;
create table test3.table3 as select * from dba_objects;

導出數據

$ exp system/oracle file=test.dmp owner=test1,test2,test3

...

About to export specified users ...
. exporting pre-schema procedural objects and actions
. exporting foreign function library names for user TEST1
. exporting foreign function library names for user TEST2
. exporting foreign function library names for user TEST3

...

Export terminated successfully without warnings.

清理數據

drop table test1.table1 purge;
drop table test2.table2 purge;
drop table test3.table3 purge;

導入數據

1.亂序導入

$ imp system/oracle fromuser=test1,test2,test3 touser=test3,test1,test2 file=test.dmp
...
. importing TEST1's objects into TEST3
. importing TEST2's objects into TEST1
. importing TEST3's objects into TEST2
... Import terminated successfully without warnings.
$ sqlplus / as sysdba SQL> select count(1) from test1.table2; COUNT(1) ---------- 87461 SQL> select count(1) from test2.table3; COUNT(1) ---------- 87461 SQL> select count(1) from test3.table1; COUNT(1) ---------- 87461

總結:導入的時候不會主動識別用戶名進行匹配,而是根據fromuser和touser的排列按順序匹配進行導入。

2.fromuser<touser

清理數據:
drop table test1.table2 purge;
drop table test2.table3 purge;
drop table test3.table1 purge;
導入: $ imp system
/oracle fromuser=test1,test2 touser=test1,test2,test3 file=test.dmp ... . importing TEST1's objects into TEST1 . importing TEST2's objects into TEST2 ... Import terminated successfully without warnings.
驗證: SQL
> select owner,table_name from dba_tables where owner in ('TEST1','TEST2','TEST3'); OWNER TABLE_NAME ---------- ------------------------------ TEST2 TABLE2 TEST1 TABLE1

總結:當fromuser<touser時,仍然按順序匹配將fromuser下的對象導入到touser。多出的touser不作處理,不導入任何數據。

3.fromuser>touser

清理數據:
drop table test1.table1 purge;
drop table test2.table2 purge;

導入:
$ imp system/oracle fromuser=test1,test2,test3 touser=test1,test2 file=test.dmp
...
. importing TEST1's objects into TEST1
. importing TEST2's objects into TEST2
. importing TEST3's objects into TEST3
...
Import terminated successfully without warnings.

驗證:
SQL> select owner,table_name from dba_tables where owner in ('TEST1','TEST2','TEST3');

OWNER      TABLE_NAME
---------- ------------------------------
TEST1      TABLE1
TEST2      TABLE2
TEST3      TABLE3

總結:fromuser>touser時,多出的用戶會在數據庫中找到對應相同賬戶並導入數據。(相同賬戶在目標數據庫中存在的情況下)

當賬戶在目標庫中不存在時,會報錯,並忽略掉對該用戶的導入:

SQL> drop user test3 cascade;

User dropped.

$ imp system/oracle fromuser=test1,test2,test3  touser=test1,test2 file=test.dmp

...
. importing TEST1's objects into TEST1
. importing TEST2's objects into TEST2
. importing TEST3's objects into TEST3
IMP-00003: ORACLE error 1435 encountered
ORA-01435: user does not exist
....
Import terminated successfully with warnings.

SQL> select owner,table_name from dba_tables where owner in ('TEST1','TEST2','TEST3');

 
         

OWNER TABLE_NAME
---------- ------------------------------
TEST1 TABLE1
TEST2 TABLE2

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM