Oracle資料庫exp imp以使用者來匯出的執行個體 (轉)

來源:互聯網
上載者:User

標籤:

http://database.51cto.com/art/201004/196538.htm

以下的文章主要介紹Oracle資料庫exp imp按相關的使用者來匯出匯入相關執行個體,第一步我們要從一台windows伺服器 A 上匯出關於 Test1 這個使用者的所有對象,然後匯入到linux伺服器 B 上的 Test2使用者。(已知Test1密碼為Test1passwd 或者用system使用者匯出也行)

2.B機器上Test2使用者不存在,或Test2使用者已經存在 兩種情況(使用者存在相對比較複雜)

如果Test2使用者已經存在(資料沒用,可以刪除),串聯刪除使用者及所有對象(有可能遇到有人正在串連,刪除不掉的情況 方法參照下文),重新建立帳號並賦權。

3.賦予適當的許可權

操作步驟:

1.從 A 上匯出資料檔案到指定目錄(目錄名稱自己定義,只要自己能找到就行,和使用者名稱沒有關係)

  1. sqlplus /nolog   
  2. conn / as sysdba   
  3. exp Test1/Test1passwd owner=Test1 file=D:\files\Test1.dmp   

 

2.在A機器上查看使用者預設資料表空間,以便匯入時建立一樣的資料表空間

  1. SQL> select username,default_tablespace from dba_users where username =‘TEST1‘;   
  2. USERNAME DEFAULT_TABLESPACE   
  3. TEST1 CMIS   

 

3.查看使用者使用的資料表空間

  1. SQL> select DISTINCT owner ,tablespace_name from dba_extents where owner like ‘TEST1‘;   
  2. OWNER TABLESPACE_NAME   
  3. TEST1 XSL   
  4. TEST1 CMIS   

 

4.查看錶空間對應的資料檔案,以便在B上建立大小合適的資料檔案。

  1. SQL> select file_name,tablespace_name from dba_data_files where tablespace_name in (‘CMIS‘,‘XSL‘);   
  2. FILE_NAME BYTES TABLESPACE   
  3. D:ORACLEPRODUCT10.2.0ORADATACMISDBCMIS 8728346624 CMIS   
  4. D:ORACLEPRODUCT10.2.0ORADATACMISDBCMIS01.ORA 8204058624 CMIS   
  5. D:ORACLEPRODUCT10.2.0ORADATACMISDBCMIS02.ORA 4194304000 CMIS   
  6. D:ORACLEPRODUCT10.2.0ORADATACMISDBCMIS03.ORA 4194304000 CMIS   
  7. D:ORACLEPRODUCT10.2.0ORADATACMISDBCMIS04.ORA 4194304000 CMIS   
  8. D:ORACLEPRODUCT10.2.0ORADATACMISDBCMIS05.ORA 4194304000 CMIS   
  9. D:ORACLEPRODUCT10.2.0ORADATACMISDBCMIS06.ORA 4194304000 CMIS   
  10. D:ORACLEPRODUCT10.2.0ORADATACMISDBXSL.ORA 4194304000 XSL   
  11. D:ORACLEPRODUCT10.2.0ORADATACMISDBXSL01.ORA 4194304000 XSL   
  12. D:ORACLEPRODUCT10.2.0ORADATACMISDBXSL02.ORA 4194304000 XSL   
  13.  

 

 

5.檢查B機器的資料表空間,看是否存在CMIS,XSL

 

  1. select name from v$tablespace where name in (‘XSL‘,‘CMIS‘);  

尋找不到,說明沒有這個兩個資料表空間,需要建立。

6.要匯入資料的server沒有xsl,cmis資料表空間。建立

 

  1. create tablespace xsl logging datafile 
    ‘/opt/oracle/product/10.2.0/oradata/xsl.dbf‘ 
    size 15000M extent management local;   
  2. create tablespace cmis logging datafile 
    ‘/opt/oracle/product/10.2.0/oradata/cmis.dbf‘ size 37000M extent management local;   

 

7.在伺服器B上尋找使用者是否已經存在

 

  1. SQL> select username from dba_users where username=‘TEST2‘;  

接下來分為兩種情況,如果不存在那麼按照 [一] 方法,如果存在按照 [二]

建立使用者

 

  1. create user Test2 identified by Test2passwd default tablespace cmis temporary tablespace temp profile default;  

如果使用者存在

  1. drop user Test2 cascade;  

(刪除使用者及其擁有的所有對象)

此時如果這個使用者在串連,drop會出錯,必須先殺掉使用者的session,然後再drop user

 

  1. SELECT ‘alter system kill session ‘‘‘
    ||SID||‘,‘||SERIAL||‘‘‘ immediate;
    ‘ FROM V$SESSION WHERE USERNAME=‘TEST2‘;  

(如果使用者正在串連,構建命令並殺掉)

(上面的語句是構建出殺掉Test2使用者session的語句)比如:

 

  1. ‘ALTERSYSTEMKILLSESSION‘‘‘||SID||‘,‘||SERIAL||‘‘‘IMMEDIATE;‘  
  2. alter system kill session ‘129,3570‘ immediate;   
  3. alter system kill session ‘131,2‘ immediate;   
  4. alter system kill session ‘133,572‘ immediate;   
  5. alter system kill session ‘135,1456‘ immediate;   
  6. alter system kill session ‘136,487‘ immediate;   
  7. alter system kill session ‘138,302‘ immediate;   
  8. alter system kill session ‘139,366‘ immediate;   

 

再複製這些語句,粘貼到sqlplus中執行,來殺掉Test2的session。

  1. create user Test2 identified by Test2passwd default 
    tablespace cmis temporary tablespace temp profile default; 

(建立使用者)

  1. grant connect,resource to Test2;  

(授權)

8.把檔案從A機器上拷貝到B機器上。假如拷貝過來放到tmp目錄下/tmp/Test1.dmp

9.最後在A機器上按使用者匯入資料

一定注意執行imp時要退出sqlplus,在linux的shell下執行imp

 

  1. [[email protected] ~]$ imp Test2/Test2passwd fromuser 
    =Test1 touser =test2 file=D:\xsldb.DMP log =app/oracle/file/log/DEV_PMODOC.log;  

以上的相關內容就是對Oracle資料庫exp imp按使用者匯出匯入執行個體的介紹,望你能有所收穫。

Oracle資料庫exp imp以使用者來匯出的執行個體 (轉)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.