搜尋此網誌

星期四, 4月 02, 2009

Oracle 10g expdp impdb

如何使用expdb & impdb
1. 建立exp directory
exp 與 expdp 使用上,最大的不同點在於exp directory
傳統的exp 不用建立,直接在執行的語法中宣告即可,而expdb必須先行宣告在資料庫中。
建立的範例:
create directory expdb_dir as '/u01/expdb';

2. 賦與 exp directory 權限
若一般的使用者想使用此目錄,必須賦與相對應的權限
如:
grant read, write on directory expdb_dir to scott;

當然囉,DBA是有無上的權限…所以如果你是DBA身份,那就不用grant。

3. 導出 expdb 資料

有用過舊版exp 的使用者,經常作的不外乎
α、full database export
β、user export
ν、table export

這邊簡單的列出這幾種需求所執行的指令:
●full database export
expdb username/password@dbname directory=expdb_dir dumpfile=fulldb.dmp full=y
●user export
expdb username/password@dbname directory=expdb_dir dumpfile=schema.dmp schemas=scott
●table export
expdb username/password@dbname directory=expdb_dir dumpfile=table.dmp tables=emp.employer


4. 匯入 impdb 資料

匯入資料一般會作的是
α、full database import
β、user import (to another schema)
ν、table import

這邊簡單的列出這幾種需求所執行的指令:

●impdp username/password@dbname directory=expdb_dir dumpfile=fulldb.dmp full=y
●impdp username/password@dbname directory=expdb_dir dumpfile=fulldb.dmp remap_schema=source_schema:dest_schema
●impdp username/password@dbname directory=expdb_dir dumpfile=fulldb.dmp tables=my,big,list,of,tables

另外,還可以更換原先table的tablespace, 只需增加 remap_tablespace=source_tablespace:dest_tablespace即可

expdp 與 impdp 還有許多選項可以使用,請自參考expdp help=y or impdp help=y