標籤:執行 ase 10g apu 常用 dao pre asc 需要
常用命令樣本:
匯出:
expdp acl/[email protected] directory=dir schemas=acl dumpfile=ACL.DMP logfile=acl.log
匯入: impdp acl/[email protected] directory=dir schemas=acl dumpfile=ACL.DMP logfile=acl.log
注意:匯出語句後面不要有分號
Oracle資料匯入匯出之imp/exp與Expdp/impdp
需要進行oracle資料庫資料匯入匯出的時候,我們只需要將資料泵的命令寫一個批處理指令碼就可以方便的進行資料的操作。比如在windows下寫一個.bat檔案,或在linux下寫一個.sh檔案,在其中添加以下想要的命令執行即可。但expdp/impdp只能在資料庫所在的伺服器上執行匯入匯出命令。
exp/imp已經很好用了,但是唯一的缺點是速度太慢,從Oracle 10g開始提供了稱為資料泵新的工具expdp/impdp,它為Oracle資料提供高速並行及大資料的遷移。
imp/exp可以在用戶端調用,但是expdp/impdp只能在服務端,因為在使用expdp/impdp以前需要在資料庫中建立一個Directory。
Expdp/impdp
一、directory目錄:
1、查看管理員目錄(同時查看作業系統中是否存在,因為Oracle並不關心該目錄是否存在,如果不存在,則出錯)
select * from dba_directories;
2、建立資料庫指定目錄:(如果不想使用舊的目錄或不存在指定目錄) 註:一般資料庫目錄只允許sys創
create directory dir as ‘d:\dump‘; //dir名稱可以隨便命名 需要手工建立,即:create directory 別名 as ‘d:\伺服器目錄名‘,將匯入或匯出的檔案放在伺服器目錄下 。
注意:匯入時一樣要建立目錄,並將要匯入的檔案放置在建立的目錄下,而且要將匯出時產生的log也放置在下面,否則會報錯。
3、給使用者賦予在指定目錄的操作許可權,最好以system等管理員賦予。
select privilege,table_name from dba_tab_privs where grantee=‘scott‘; --查詢許可權
grant connect,resource to scott;
grant read,write on directory dir to scott; ----最少要賦予這個許可權
grant exp_full_database,imp_full_database to scott;
4、刪除自定目錄
delete directory dir;
二、匯出:
1、匯出內容相關的參數:
expdp:
匯出命令
ktrade/[email protected]:
使用者及資料庫執行個體驗證
directory=dump:
指定轉儲檔案和記錄檔所在的目錄,目錄對象是使用CREATE DIRECTORY語句建立的對象,而不是OS目錄 ?os目錄 注意:此參數需要放在靠前的位置,在後面有可能會報錯ORA-39002: 操作無效
schemas: schemas=ktrade 註:匯出執行個體下的所有對象
dumpfile:
用於指定轉儲檔案的名稱,預設名稱為expdat.dmp
DUMPFILE=[directory_object:]file_name [,….]
Directory_object用於指定目錄對象名,file_name用於指定轉儲檔案名稱,如果不指定directory_object,匯出會自動使用DIRECTORY選項指定的目錄對象
logfile:
指定匯出記錄檔檔案的名稱,預設名稱為export.log
LOGFILE=[directory_object:]file_name
Directory_object用於指定目錄對象名稱,file_name用於指定匯出記錄檔名.如果不指定directory_object.匯出會自動使用DIRECTORY的相應選項值.
content: content=metadata_only:匯出表結構 content=data_only:匯出表資料 content=all:匯出表結構+表資料 註:如果不指定content,預設情況下是all
tables: tables=tablename1,tablename2 註:如果不寫,預設情況下匯出模式下所有
full: full=y 註:匯出全庫,要求使用較高許可權的sys或system使用者
parallel: parallel=:並行度設定,根據cpu的數量設定
tablespace: tablespace=:匯出資料表空間內的所有資料
transport_tablespaces: transport_tablespaces=:匯出資料表空間的定義,用於資料表空間傳輸
parfile: parfile=:可以將參數檔案在檔案中載入
query: query="where id=20":用於按條件查詢,在按表匯出時用到
filesize:
指定匯出檔案的最大尺寸,預設為0,(表示檔案尺寸沒有限制)
job_name:
指定要匯出作用的名稱,預設為SYS_EXPORT_SCHEMA_01
JOB_NAME=jobname_string
SELECT * FROM DBA_DATAPUMP_JOBS;--查看存在的job
2、樣本:
以SID=orcl,匯出dmp的帳號為test,匯入dmp的帳號為test為例。
若將資料從sfz中匯出:
expdp test/[email protected] directory=別名 dumpfile=匯出檔案名稱
1)按使用者導
expdp scott/[email protected] directory=dir dumpfile=expdp.dmp schemas=scott logfile=expdp.log
2)並行進程parallel
expdp scott/[email protected] directory=dir dumpfile=scott3.dmp parallel=40 job_name=scott3 logfile=expdp.log
3)按表名導
expdp scott/[email protected] directory=dir dumpfile=expdp.dmp tables=emp,dept logfile=expdp.log
4)按查詢條件導
expdp scott/[email protected] directory=dir dumpfile=expdp.dmp tables=emp query=‘WHERE deptno=20‘
5)按資料表空間導
expdp system/manager directory=dir dumpfile=expdp.dmp tablespaces=temp,example
6)導整個資料庫
expdp system/manager directory=dir dumpfile=full.dmp full=y
三、匯入:
1、匯入內容相關的參數:
impdp:
匯入命令
remap_schema:
該選項用於將源方案的所有對象裝載到目標方案中(當兩個方案名稱不同時).
remap_schema=source_schema:target_schema
remap_tablespace:
將源資料表空間的所有對象匯入到目標資料表空間中(當兩個資料表空間名稱不同時)
remap_tablespace=source_tablespace:target:tablespace
remap_datafile:
該選項用於將來源資料檔案名稱轉變為目標資料檔案名,在不同平台之間搬移資料表空間時可能需要該選項.
remap_datafile=source_datafie:target_datafile
2、樣本:
注意:如果匯入的資料庫是建立資料庫,那麼需要先建立資料表空間,以及使用者,如下面這樣:
drop tablespace koauth24 including contents and datafiles;create tablespace koauth24 datafile ‘F:\app\Administrator\product\4.0data\koauth24‘ size 100M autoextend on next 100M;drop user koauth24 cascade;create user koauth24 identified by kingddom88 default tablespace koauth24;grant dba,resource,connect to koauth24;grant select any table to koauth24;grant update any table to koauth24;grant insert any table to koauth24;
1)導到指定使用者下
impdp scott/[email protected] directory=dir dumpfile=expdp.dmp SCHEMAS=scott logfile=impdp.log
2)改變表的owner
impdp system/manager directory=dir dumpfile=expdp.dmp TABLES=scott.dept REMAP_SCHEMA=scott:system;
3)匯入資料表空間
impdp system/manager directory=dir dumpfile=tablespace.dmp TABLESPACES=example;
4)匯入資料庫
impdb system/manager directory=dump_dir dumpfile=full.dmp FULL=y;
5)追加資料
impdp system/manager directory=dir DUMPFILE=expdp.dmp SCHEMAS=system TABLE_EXISTS_ACTION
6、匯入時使用者名稱、資料表空間名稱等不一樣時,可做個映射
remap_schema=test(匯出的名稱):test1(將要匯入的名稱)
remap_tablespace=oauth2:koauth2
最後可以檢查一下資料庫中是不是所有表都有了,不足的可以再補齊。
imp/exp
一、資料匯出:
1 將資料庫TEST完全匯出,使用者名稱system 密碼manager 匯出到D:\daochu.dmp中
exp system/[email protected] file=d:\daochu.dmp full=y
2 將資料庫中system使用者與sys使用者的表匯出
exp system/[email protected] file=d:\daochu.dmp owner=(system,sys)
3 將資料庫中的表table1 、table2匯出
exp system/[email protected] file=d:\daochu.dmp tables=(table1,table2)
4 將資料庫中的表table1中的欄位filed1以"00"打頭的資料匯出
exp system/[email protected] file=d:\daochu.dmp tables=(table1) query=\" where filed1 like ‘00%‘\"
上面是常用的匯出,對於壓縮我不太在意,用winzip把dmp檔案可以很好的壓縮。不過在上面命令後面 加上 compress=y 就可以了
二、資料的匯入:
1 將D:\daochu.dmp 中的資料匯入 TEST資料庫中。
imp system/[email protected] file=d:\daochu.dmp
上面可能有點問題,因為有的表已經存在,然後它就報錯,對該表就不進行匯入。
在後面加上 ignore=y 就可以了。
2 將d:\daochu.dmp中的表table1 匯入
imp system/[email protected] file=d:\daochu.dmp tables=(table1)
注意:基本上上面的匯入匯出夠用了。不少情況我是將表徹底刪除,然後匯入。
同名使用者之間的資料匯入:
imp hkb/[email protected] file=c:\orabackup\hkbfull.dmp log=c:\orabackup\hkbimp.log full=y
不同名之間的資料匯入:
imp system/[email protected] fromuser=hkb touser=hkb_new file=c:\orabackup\hkbfull.dmp
log=c:\orabackup\hkbimp.log;
oracle資料庫的匯入匯出