expdp导出表结构_(转)oracle使用expdp、impdp和exp、imp导入导出表及表结构
使用expdp、impdp和exp、imp時(shí)應(yīng)該注重的事項(xiàng):
1、exp和imp是客戶端工具程序,它們既可以在客戶端使用,也可以在服務(wù)端使用。
2、expdp和impdp是服務(wù)端的工具程序,他們只能在oracle服務(wù)端使用,不能在客戶端使用。
3、imp只適用于exp導(dǎo)出的文件,不適用于expdp導(dǎo)出文件;impdp只適用于expdp導(dǎo)出的文件,而不適用于exp導(dǎo)出文件。
4、對于10g以上的服務(wù)器,使用exp通常不能導(dǎo)出0行數(shù)據(jù)的空表,而此時(shí)必須使用expdp導(dǎo)出。
exp、imp導(dǎo)入導(dǎo)出
sqlplus 進(jìn)入數(shù)據(jù)庫中
導(dǎo)出
直接在命令行下寫命令
1.導(dǎo)出自己的表
exp userid=scott/tiger@myoral tables=(emp,dept) file=/opt/e1.dmp
2.導(dǎo)出其它方案的表 如果用戶要導(dǎo)出其它方案的表,則需要dba的權(quán)限或是exp_full_database的權(quán)限,比如system就可以導(dǎo)出scott的表
exp userid=system/manager@myoral tables=(scott.emp) file=d:\e2.emp
3. 導(dǎo)出表的結(jié)構(gòu)
exp userid=scott/tiger@accp tables=(emp) file=/opt/e3.dmp rows=n
4. 使用直接導(dǎo)出方式
exp userid=scott/tiger@accp tables=(emp) file=/opt/e4.dmp direct=y
這種方式比默認(rèn)的常規(guī)方式速度要快,當(dāng)數(shù)據(jù)量大時(shí),可以考慮使用這樣的方法。 這時(shí)需要數(shù)據(jù)庫的字符集要與客戶端字符集完全一致,否則會報(bào)錯(cuò)
導(dǎo)出方案 導(dǎo)出方案是指使用export工具導(dǎo)出一個(gè)方案或是多個(gè)方案中的所有對象(表,索引,約束...)和數(shù)據(jù)。并存放到文件中
1. 導(dǎo)出自己的方案
exp userid=scott/tiger@myorcl owner=scott file=/opt/scott.dmp
2. 導(dǎo)出其它方案 如果用戶要導(dǎo)出其它方案,則需要dba的權(quán)限或是exp_full_database的權(quán)限,比如system用戶可以導(dǎo)出任何方案
exp userid=system/manager@myorcl owner=(system,scott) file=/opt/system.dmp
導(dǎo)出數(shù)據(jù)庫
導(dǎo)出數(shù)據(jù)庫是指利用export導(dǎo)出所有數(shù)據(jù)庫中的對象及數(shù)據(jù),要求該用戶具有dba的權(quán)限或者是exp_full_database權(quán)限 增量備份(好處是第一次備份后,第二次備份就快很多了)
exp userid=system/manager@myorcl full=y inctype=complete file=/opt/all.dmp
導(dǎo)入
1. 導(dǎo)入自己的表
imp userid=scott/tiger@myorcl tables=(emp) file=/opt/xx.dmp
2. 導(dǎo)入表到其它用戶 要求該用戶具有dba的權(quán)限
imp_full_database imp userid=system/tiger@myorcl tables=(emp) file=/opt/xx.dmp touser=scott
3. 導(dǎo)入表的結(jié)構(gòu),只導(dǎo)入表的結(jié)構(gòu)而不導(dǎo)入數(shù)據(jù)
imp userid=scott/tiger@myorcl tables=(emp) file=/opt/xx.dmp rows=n
4. 導(dǎo)入數(shù)據(jù) 如果對象(如比表)已經(jīng)存在可以只導(dǎo)入表的數(shù)據(jù)
imp userid=scott/tiger@myorcl tables=(emp) file=/opt/xx.dmp ignore=y
導(dǎo)入方案 導(dǎo)入方案是指使用import工具將文件中的對象和數(shù)據(jù)導(dǎo)入到一個(gè)或是多個(gè)方案中。如果要導(dǎo)入其它方案,要求該用戶具有dba的權(quán)限,或者imp_full_database
1. 導(dǎo)入自身的方案
imp userid=scott/tiger file=/opt/xxx.dmp
2. 導(dǎo)入其它方案 要求該用戶具有dba的權(quán)限
imp userid=system/manager file=/opt/xxx.dmp fromuser=system touser=scott
導(dǎo)入數(shù)據(jù)庫
在默認(rèn)情況下,當(dāng)導(dǎo)入數(shù)據(jù)庫時(shí),會導(dǎo)入所有對象結(jié)構(gòu)和數(shù)據(jù),案例如下:
imp userid=system/manager full=y file=/opt/xxx.dmp
expdp、impdp導(dǎo)入導(dǎo)出
一、準(zhǔn)備工作
1)、在備份目的路徑建立備份文件夾
例如:d:\bak
2)、用sys用戶在oracle中創(chuàng)建邏輯目錄
SQL>create directory oracleBak_dir as ‘d:\bak’;
3)、查看數(shù)據(jù)庫中的邏輯目錄
SQL>select * from dba_directories;
4)、授權(quán)用戶有對邏輯目錄的讀寫權(quán)限
SQL>grant read,write on directory oracleBak_dir to someone;
二、導(dǎo)出
1)導(dǎo)出用戶
expdp scott/tiger@orcl schemas=scott dumpfile=expdp.dmp directory=oracleBak_dir ;
2)導(dǎo)出表
expdp scott/tiger@orcl tables=emp,dept dumpfile=expdp.dmp directory=oracleBak_dir ;
3)按查詢條件導(dǎo)
expdp scott/tiger@orcl directory=oracleBak_dir dumpfile=expdp.dmp tables=emp query=’where deptno=20’;
4)按表空間導(dǎo)
expdp system/manager@orcl directory=oracleBak_dir dumpfile=tablespace.dmp tablespaces=temp,example;
5)導(dǎo)整個(gè)數(shù)據(jù)庫
expdp system/manager@orcl directory=oracleBak_dir dumpfile=full.dmp full=y;
三、導(dǎo)入數(shù)據(jù)
1)導(dǎo)入用戶(從用戶scott導(dǎo)入到用戶scott)
impdp scott/tiger@orcl directory=oracleBak_dir dumpfile=expdp.dmp schemas=scott;
2)導(dǎo)入表(從scott用戶中把表dept和emp導(dǎo)入到system用戶中)
impdp system/manager@orcl directory=oracleBak_dir dumpfile=expdp.dmp tables=scott.dept,scott.emp remap_schema=scott:system;
3)導(dǎo)入表空間
impdp system/manager@orcl directory=oracleBak_dir dumpfile=tablespace.dmp tablespaces=example;
4)導(dǎo)入數(shù)據(jù)庫
impdb system/manager@orcl directory=oracleBak_dir dumpfile=full.dmp full=y;
5)追加數(shù)據(jù)
impdp system/manager@orcl directory=dump_dir dumpfile=expdp.dmp schemas=systemtable_exists_action
參考文檔:
http://docs.oracle.com/cd/B19306_01/server.102/b14215/dp_export.htm#i1007509
http://docs.oracle.com/cd/B19306_01/server.102/b14215/dp_import.htm#g1025464
總結(jié)
以上是生活随笔為你收集整理的expdp导出表结构_(转)oracle使用expdp、impdp和exp、imp导入导出表及表结构的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C语言学习及应用笔记之二:C语言stat
- 下一篇: go 单元测试 testing 打印输出