Oracle新建用戶並且將已有的數據dmp文件導入到新建的用戶下的操作流程 1.切換到oracle用戶下 su - oracle 2.登錄sqlplus sqlplus /nolog 3.使用sysdba登錄 conn /as sysdba 4.查詢表空間存儲位置 select name from v$tempfile; 5、創建臨時表空間 create temporary tablespace TMP_CAL tempfile '/home/oracle/tablespace/TMP_CAL_01.dbf' size 2G reuse autoextend on next 20m maxsize unlimited; 6、創建數據表空間 create tablespace DATA_AML_BUSI datafile '/home/oracle/tablespace/DATA_AML_BUSI_01.dbf' size 100M reuse autoextend on next 40M maxsize unlimited; 7、創建索引表空間 create tablespace IDX_BUSI logging datafile '/home/oracle/tablespace/INDEX_01.dbf' size 100m autoextend on next 32m maxsize 2048m extent management local; 8、創建用戶並分配表空間 create user aml3 identified by aml3 default tablespace DATA_AML_BUSI temporary tablespace TMP_CAL; 9、賦權dba給用戶 grant dba to aml3; 10、創建文件目錄 create directory DATA_DIR as '/home/oracle/temp'; 11、給用戶賦文件目錄的讀寫權限 grant read,write on directory dir to system; 1、導入dmp文件 方式一:同名同庫同空間的 impdp aml/aml@orcl directory=DATA_DIR dumpfile=aml_v2.dmp 方式二:不同名,不同表空間,不同用戶 impdp aml3/aml3@orcl transform=segment_attributes:n directory=DATA_DIR dumpfile=aml_v2.dmp remap_tablespace=DATA_BUSI:DATA_AML_BUSI remap_schema=aml:aml3 logfile=exdp.log; ----remap_tablespace=DATA_BUSI:DATA_AML_BUSI 將數據的tablespace 從a 轉換為b ----remap_schema=aml:aml3 將數據的schema從a 轉換為b /************************************************/ / Oracle 常用操作指南 / /************************************************/ --1、查詢原數據庫信息 --1.1查詢數據庫實例名 select name from v$database; --1.2查詢數據庫字符集 select * from nls_database_parameters t where t.PARAMETER='NLS_CHARACTERSET'; --1.4查詢數據庫中自己創建的用戶 select * from all_users t order by t.created desc; --1.5查詢用戶對應的表空間 select * from dba_users t where t.username ='AML'; --1.6查詢臨時表空間和表空間的存儲位置 select * from user_tablespaces select name from v$tempfile; --1.7刪除表空間 drop tablespace TMP_CAL including contents and datafiles; --1.8查詢文件目錄位置 select * from dba_directories; /************************************************/ / Oracle 數據泵導入導出指南 / /************************************************/ 一、新建邏輯目錄 以system等管理員創建邏輯目錄,Oracle不會自動創建實際的物理目錄“D:\oracleData”(務必手動創建此目錄),僅僅是進行定義邏輯路徑dump_dir; sql>create directory dump_dir as 'D:\oracleData'; 二、查看管理員目錄(同時查看操作系統是否存在該目錄,因為oracle並不關心該目錄是否存在,假如不存在,則出錯) sql>select * from dba_directories; 三、用expdp導出數據 1)導出用戶及其對象 expdp scott/tiger@orcl schemas=scott dumpfile=expdp.dmp directory=dump_dir; 2)導出指定表 expdp scott/tiger@orcl tables=emp,dept dumpfile=expdp.dmp directory=dump_dir; 3)按查詢條件導 expdp scott/tiger@orcl directory=dump_dir dumpfile=expdp.dmp tables=empquery='where deptno=20'; 4)按表空間導 expdp system/manager@orcl directory=dump_dir dumpfile=tablespace.dmp tablespaces=temp,example; 5)導整個數據庫 expdp system/manager@orcl directory=dump_dir dumpfile=full.dmp full=y; 6)導出每個表里的20條數據 expdp ncms_yn/ncms_yn@yndw1 dumpfile=NCMS_YN.dmp DIRECTORY=EXPDP_DIR QUERY=\"WHERE ROWNUM \<21\" 四、用impdp導入數據 在正式導入數據前,要先確保要導入的用戶已存在,如果沒有存在,請先用下述命令進行新建用戶 --創建表空間 create tablespace tb_name datafile 'D:\tablespace\tb_name.dbf' size 1024m AUTOEXTEND ON; --創建用戶 create user user_name identified by A123456a default tablespace tb_name temporary tablespace TEMP; --給用戶授權 sql>grant read,write on directory dump_dir to user_name; sql>grant dba,resource,unlimited tablespace to user_name; 1)導入用戶(從用戶scott導入到用戶scott) impdp scott/tiger@orcl directory=dump_dir dumpfile=expdp.dmp schemas=scott; 2)導入表(從scott用戶中把表dept和emp導入到system用戶中) impdp system/manager@orcl directory=dump_dir dumpfile=expdp.dmptables=scott.dept,scott.emp remap_schema=scott:system; 3)導入表空間 impdp system/manager@orcl directory=dump_dir dumpfile=tablespace.dmp tablespaces=example; 4)導入數據庫 impdb system/manager@orcl directory=dump_dir dumpfile=full.dmp full=y; 5)追加數據 impdp system/manager@orcl directory=dump_dir dumpfile=expdp.dmp schemas=systemtable_exists_action