Linux伺服器下對Oracle資料庫expdp(匯出)和impdp(匯入)

來源:互聯網
上載者:User

標籤:shel   資料庫名   rar   root   lis   nec   服務   font   linu   

      緊接上篇文章,Oracle資料庫結構描述已經建立完成,我的需求是:將老伺服器上的資料庫遷移到新的資料庫上。

這就用到impdp(匯入)操作。

要想實現對新資料庫的impdp(匯入)工作,

首先需要從老的資料庫上做expdp(匯出)操作,命令如下:

      expdp 使用者名稱/密碼 schemas=iirspublish dumpfile=匯出資料庫名.dmp DIRECTORY=目錄名 logfile=匯出日誌.log

     備忘:schemas,你用“使用者 user”來理解就很容易了,每個模式(user)下可以有一套互不干擾的對象。

    你如果想要訪問其他模式的對象,需要指定schema的name,實際就是指定username。

下面這些步驟是我在實際工作中實踐過的,

準備工作:首先用Xshell串連到Linux伺服器,並切換至oracle帳號,

[[email protected] ~]# su - oracle

Last login: Fri Jul 21 13:49:22 CST 2017 on pts/1    (成功切換)

[[email protected] ~]$ sqlplus sys/ as sysdba

切換到

SQL>

然後依次執行如下命令:

1、sys使用者登入建立目錄

SQL>create directory dir_iirsuserbaknew as ‘/u01/app/oracle/oradata‘; (建立目錄並分配存放路徑)

2、sys使用者下建立資料表空間

SQL>create tablespace IIRSUSER datafile ‘/u01/app/oracle/oradata/IIRSUSER01‘ size 100m Autoextend on next 100m,‘/u01/app/oracle/oradata/IIRSUSER02‘ size 100m Autoextend on next 100m Extent management local uniform size 200k;(建立資料表空間,設定檔案自動成長空間大小)

3、sys使用者下建立使用者

SQL>create user iirsuser identified by "iirsuser" Default tablespace IIRSUSER Temporary tablespace temp; (建立使用者名稱,設定密碼,並指明預設資料表空間和暫存資料表空間)

SQL>grant dba,connect,resource to iirsuser; (給使用者授予dba、基礎、開發許可權)

4、sys使用者下

SQL>Grant read,write on directory dir_iirsuserbaknew to iirsuser;  (將目錄的讀寫權限授予使用者)

5、DOS下Impdp還原                                                        

[[email protected] ~]$impdp iirsuser/"iirsuser"@orcl directory=dir_iirsuserbaknew dumpfile=ExpIirspublish20170814.dmp remap_tablespace=IIRSPublish:IIRSUSER remap_schema=iirspublish:iirsuser logfile=impdbiirspublish20170814.log transform=oid:n

第5步需要退出(exit)SQL命令列至Oracle帳號下執行。

需要解釋的是:

impdp 使用者名稱/"密碼"@sid directory=目錄 dumpfile=老資料庫expdp得到的執行個體名.dmp remap_tablespace=老資料庫空間名:新資料庫空間名 remap_schema=老資料庫使用者名稱:新資料庫使用者名稱 logfile=impdb日誌名.log transform=該參數可以去掉,應用於適用對象的中繼資料轉換

需要強調的是:

問題1:如果你在操作的過程中忘記了自己建的目錄,可以用命令(select * from dba_directories;)查詢;

問題2:如果想刪除新還原好的資料庫執行個體,那麼需要執行以下操作

1)、首先刪除使用者

-----drop USER c#iirsuser CASCADE;

2)、其次刪除資料表空間包括資料表空間的內容和資料檔案

-----drop tablespace IIRSUSER including contents and datafiles cascade constraints;

3)、最後刪除目錄

-----drop directory dir_iirsuserbaknew;

 

Linux伺服器下對Oracle資料庫expdp(匯出)和impdp(匯入)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.