標籤:ima com evel taf extent def color 暫存資料表 檔案
在Oracle資料庫中可以使用imp和exp命令來執行資料的匯入匯出(包括表結構和資料),使用imp和exp命令執行匯入匯出操作必需的是需要安裝Oracle資料庫,系統安裝Oracle資料庫,可以識別 dmp / imp 命令,否則系統會不識別imp和exp命令,如下左圖所示:
裝好Oracle後,使用資料庫連接工具串連好資料庫(我自己使用的是sqldeveloper),執行匯入匯出命令:
匯出:
1. 開啟cmd;
2. 執行命令。命令格式:exp 使用者名稱/密碼@資料庫IP地址/實力名 file=匯出檔案路徑\檔案名稱.dmp owner=使用者名稱
例如:exp CUSTOMER_SERVICE_ROOT/[email protected]/fdms2 file=C:\Users\Administrator\Desktop\20180202.dmp owner=CUSTOMER_SERVICE_ROOT 此處的fdms2是資料庫名,此處匯出的是整個資料庫,若有選擇性的匯出部分表結構和資料則執行下面的命令:
exp CUSTOMER_SERVICE_ROOT/[email protected]/fdms2 file=C:\Users\Administrator\Desktop\20180202.dmp tables=(AAAA,BBBB)
注意:在執行匯出整個資料庫時,有些表是空表,沒有資料,匯出資料時,空表是不會被執行匯出的,此時需要對空表做一定的處理:
1. 執行sql :select table_name from user_tables where NUM_ROWS=0;
select ‘alter table ‘||table_name||‘ allocate extent;‘ from user_tables where num_rows=0;
2. 將步驟1中執行的sql結果複製繼續執行,然後執行匯出命令即可匯出表結構和資料。
匯入:
1.--DBCA 建立Orcl執行個體
2. --資料庫連接工具 sys使用者登入
3.--建立暫存資料表空間(可不做)
create temporary tablespace myth_temp tempfile ‘C:\Oracle_space\myth_temp_20171116.dbf‘
size 100m autoextend on next 50m maxsize 200m;
4.--建立資料表空間
create tablespace myth datafile ‘C:\Oracle_space\myth_20171116.dbf‘
size 200m autoextend on next 100m maxsize 400m;
5--擴充資料表空間(輔助操作,可不做)
alter tablespace myth add datafile ‘C:\Oracle_space\myth_20171116.dbf‘
size 200m autoextend on;
6--建立使用者並制定資料表空間
create user username identified by 123456 default tablespace myth
temporary tablespace myth_temp
7.--賦權
grant dba to username
8.--WIN + R
9.--CMD
10.--匯入命令
imp 新使用者名稱/密碼@執行個體名 file=dmp檔案路徑\檔案名稱.dmp fromuser=匯出時的使用者名稱 touser=新使用者名稱
imp uwp_cfgh_root/[email protected] file=C:\server\201711088.dmp fromuser=uwp_cfgh_root touser=uwp_cfgh_root
若執行匯入部分表結構和資料則用下面的命令:
imp CUSTOMER_SERVICE_ROOT/[email protected]/fdms2 file=C:\Users\Administrator\Desktop\20180202.dmp tables=(AAAA,BBBB);
參考文檔地址:http://blog.csdn.net/micholas_net/article/details/78714589
http://blog.csdn.net/menghuannvxia/article/details/51076930
Oracle資料庫中表的imp&exp